Skip to content

feat: Enable DFlash on tool calling for Nemotron - #1234

Open
julianxhokaxhiu wants to merge 1 commit into
ROCm:mainfrom
julianxhokaxhiu:feat/nemotron-dflash
Open

julianxhokaxhiu wants to merge 1 commit into
ROCm:mainfrom
julianxhokaxhiu:feat/nemotron-dflash

Conversation

@julianxhokaxhiu

@julianxhokaxhiu julianxhokaxhiu commented Dec 3, 2026 •

Copy link
Copy Markdown

This PR has been assisted using GPT-6.1 Sol

Motivation

Enable DFlash speculative decoding for Nemotron Bolt tool calls and JSON output. Previously, decoding constraints disabled speculation for the entire response.

Technical Details

  • Sample each verification row through the active constraint.
  • Account for earlier tokens in a batch when enforcing min_tokens.
  • Publish log probabilities per token for streaming.
  • Add host-side tests and update the model documentation.

Test Plan

I built a simple Python script that tested the bottleneck of DFlash, which was around tool calling. The measured output confirms that the LLM works as expected and the speedup gain can be proofed.

Test Result

Python Script:

import csv
import json
import statistics
import time
import urllib.request

model = "nemotron3.5-bolt-dflash:e4b"
url = "http://127.0.0.1:52625/v1/chat/completions"
prompts = [
    "Write a Python function that validates an email address. Include tests.",
    "Write a Python function that merges overlapping intervals. Include tests.",
    "Write a Python function implementing binary search. Include tests.",
]
tool = {
    "type": "function",
    "function": {
        "name": "write_file",
        "description": "Write code to a file",
        "parameters": {
            "type": "object",
            "properties": {
                "path": {"type": "string"},
                "content": {"type": "string"},
            },
            "required": ["path", "content"],
        },
    },
}

csv_file = open("results.csv", "w", newline="", encoding="utf-8")
writer = csv.writer(csv_file)
writer.writerow(["prompt", "run", "tokens", "decode_seconds", "decode_tps", "wall_seconds"])
csv_file.flush()

for i, prompt in enumerate(prompts):
    body = {
        "model": model,
        "messages": [{"role": "user", "content": prompt}],
        "tools": [tool],
        "tool_choice": {"type": "function", "function": {"name": "write_file"}},
        "think": False,
        "temperature": 0,
        "max_tokens": 4096,
    }
    rates, walls = [], []
    for run in range(4):  # first run warms up; next three are measured
        label = "warmup" if run == 0 else f"run {run}/3"
        print(f"prompt {i}: starting {label}...", flush=True)
        request = urllib.request.Request(
            url, data=json.dumps(body).encode(),
            headers={"Content-Type": "application/json"},
        )
        start = time.perf_counter()
        with urllib.request.urlopen(request, timeout=600) as response:
            result = json.load(response)
        wall = time.perf_counter() - start
        choice = result["choices"][0]
        if choice["finish_reason"] != "tool_calls":
            raise RuntimeError(
                f"Prompt {i}, run {run}: unexpected finish {choice['finish_reason']!r}; "
                f"usage: {result.get('usage')}"
            )
        calls = choice["message"]["tool_calls"]
        if len(calls) != 1 or calls[0]["function"]["name"] != "write_file":
            raise RuntimeError(f"Unexpected tool calls: {calls}")
        args = json.loads(calls[0]["function"]["arguments"])
        if not isinstance(args.get("path"), str) or not isinstance(args.get("content"), str):
            raise RuntimeError(f"Invalid arguments: {args}")

        usage = result["usage"]
        print(f"prompt {i}: {label} finished in {wall:.2f} s "
              f"({usage['completion_tokens']} tokens)", flush=True)
        if run:
            rates.append(usage["decoding_speed_tps"])
            walls.append(wall)
            writer.writerow([i, run, usage["completion_tokens"],
                             usage["decoding_duration"], rates[-1], wall])
            csv_file.flush()
    print(f"prompt {i}: median decode {statistics.median(rates):.2f} tok/s; "
          f"median wall {statistics.median(walls):.2f} s", flush=True)

csv_file.close()

BEFORE

prompt 0: starting warmup...
prompt 0: warmup finished in 102.98 s (677 tokens)
prompt 0: starting run 1/3...
prompt 0: run 1/3 finished in 141.09 s (677 tokens)
prompt 0: starting run 2/3...
prompt 0: run 2/3 finished in 141.03 s (677 tokens)
prompt 0: starting run 3/3...
prompt 0: run 3/3 finished in 55.05 s (677 tokens)
prompt 0: median decode 12.60 tok/s; median wall 141.03 s
prompt 1: starting warmup...
prompt 1: warmup finished in 88.66 s (1088 tokens)
prompt 1: starting run 1/3...
prompt 1: run 1/3 finished in 88.69 s (1088 tokens)
prompt 1: starting run 2/3...
prompt 1: run 2/3 finished in 88.77 s (1088 tokens)
prompt 1: starting run 3/3...
prompt 1: run 3/3 finished in 88.60 s (1088 tokens)
prompt 1: median decode 12.47 tok/s; median wall 88.69 s
prompt 2: starting warmup...
prompt 2: warmup finished in 85.36 s (1049 tokens)
prompt 2: starting run 1/3...
prompt 2: run 1/3 finished in 85.35 s (1049 tokens)
prompt 2: starting run 2/3...
prompt 2: run 2/3 finished in 85.20 s (1049 tokens)
prompt 2: starting run 3/3...
prompt 2: run 3/3 finished in 85.23 s (1049 tokens)
prompt 2: median decode 12.52 tok/s; median wall 85.23 s

prompt,run,tokens,decode_seconds,decode_tps,wall_seconds
0,1,677,53.671744,12.613713465319853,141.0912148999996
0,2,677,53.73164,12.599652644140397,141.0293601999947
0,3,677,53.710284,12.604662451607963,55.04504889999953
1,1,1088,87.2548,12.469228053929411,88.69473989999824
1,2,1088,87.31296,12.460922181540976,88.7715240999969
1,3,1088,87.134144,12.486494387320773,88.60271839999768
2,1,1049,83.890896,12.504336584985335,85.34792429999652
2,2,1049,83.740248,12.52683178105706,85.20063880000089
2,3,1049,83.777696,12.521232381468213,85.22588139999425

AFTER

prompt 0: starting warmup...
prompt 0: warmup finished in 23.84 s (672 tokens)
prompt 0: starting run 1/3...
prompt 0: run 1/3 finished in 22.44 s (672 tokens)
prompt 0: starting run 2/3...
prompt 0: run 2/3 finished in 22.55 s (672 tokens)
prompt 0: starting run 3/3...
prompt 0: run 3/3 finished in 22.53 s (672 tokens)
prompt 0: median decode 31.46 tok/s; median wall 22.53 s
prompt 1: starting warmup...
prompt 1: warmup finished in 28.17 s (1084 tokens)
prompt 1: starting run 1/3...
prompt 1: run 1/3 finished in 27.85 s (1084 tokens)
prompt 1: starting run 2/3...
prompt 1: run 2/3 finished in 27.83 s (1084 tokens)
prompt 1: starting run 3/3...
prompt 1: run 3/3 finished in 27.84 s (1084 tokens)
prompt 1: median decode 40.73 tok/s; median wall 27.84 s
prompt 2: starting warmup...
prompt 2: warmup finished in 18.09 s (681 tokens)
prompt 2: starting run 1/3...
prompt 2: run 1/3 finished in 18.00 s (681 tokens)
prompt 2: starting run 2/3...
prompt 2: run 2/3 finished in 17.95 s (681 tokens)
prompt 2: starting run 3/3...
prompt 2: run 3/3 finished in 17.97 s (681 tokens)
prompt 2: median decode 40.51 tok/s; median wall 17.97 s

prompt,run,tokens,decode_seconds,decode_tps,wall_seconds
0,1,672,21.26936,31.594744740791448,22.44476919999579
0,2,672,21.37235,31.442494625064626,22.54890190000151
0,3,672,21.35836,31.463089862704816,22.52600810000149
1,1,1084,26.617064,40.72575397496884,27.854965899998206
1,2,1084,26.6294,40.70688787580644,27.8335522999987
1,3,1084,26.599098,40.753261633157635,27.840523799997754
2,1,681,16.809708,40.512303961496535,18.001954499995918
2,2,681,16.796512,40.54413201979078,17.954847599998175
2,3,681,16.81407,40.50179403321147,17.973085400000855

Submission Checklist

@julianxhokaxhiu julianxhokaxhiu changed the title feat: Enable DFlash on tool calling for Gemma/Nemotron feat: Enable DFlash on tool calling for Nemotron Dec 3, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant