Class Qwen
java.lang.Object
smile.llm.model.qwen.Qwen
- All Implemented Interfaces:
AutoCloseable, ModelExecutor, LanguageModel
Qwen3.5 hybrid text model (Gated DeltaNet + gated full attention).
-
Constructor Summary
ConstructorsConstructorDescriptionQwen(String name, QwenModel[] models, TensorParallelGroup tpGroup, Tokenizer tokenizer, QwenModelArgs params) Tensor-parallel constructor.Qwen(String name, QwenModel[] models, TensorParallelGroup tpGroup, Tokenizer tokenizer, QwenModelArgs params, QwenVisionArgs visionArgs, QwenVlProcessor vlProcessor) Multimodal constructor.Qwen(String name, QwenModel model, Tokenizer tokenizer, QwenModelArgs params) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionintbind(int[] prompt, int totalCapacity) Binds one request into the KV pool (multi-request safe).static QwenBuilds a Qwen instance from a HuggingFace checkpoint directory.static Qwenbuild(String checkpointDir, int maxBatchSize, int maxSeqLen, byte deviceId, double memFractionStatic, String kvCacheDtype) Builds a Qwen instance from a HuggingFace checkpoint directory.static Qwenbuild(String checkpointDir, int maxBatchSize, int maxSeqLen, byte deviceId, double memFractionStatic, String kvCacheDtype, int pageSize, ParallelConfig parallel) Builds a Qwen instance with optional tensor parallelism and KV page size.static Qwenbuild(String checkpointDir, int maxBatchSize, int maxSeqLen, byte deviceId, double memFractionStatic, String kvCacheDtype, int pageSize, ParallelConfig parallel, int modelLoaderThreads) Builds a Qwen instance with optional tensor parallelism, KV page size, and safetensors loader concurrency.static Qwenbuild(String checkpointDir, int maxBatchSize, int maxSeqLen, byte deviceId, double memFractionStatic, String kvCacheDtype, int pageSize, ParallelConfig parallel, int modelLoaderThreads, int speculativeRows, int speculativeDepth) Like the overload above, additionally reserving DeltaNet checkpoint memory for batched MTP speculation before the KV pool is sized, so the KV budget accounts for it and a large speculating cohort never has to fall back to plain decode for lack of memory.static Qwenbuild(String checkpointDir, int maxBatchSize, int maxSeqLen, byte deviceId, double memFractionStatic, String kvCacheDtype, ParallelConfig parallel) Builds a Qwen instance with optional tensor parallelism.chat(Message[] dialog, int maxGenLen, double temperature, double topp, boolean logprobs, long seed, GenerationListener listener, BooleanSupplier cancelRequested) Generates an assistant reply for a dialog.voidclose()complete(String prompt, int maxGenLen, double temperature, double topp, boolean logprobs, long seed, GenerationListener listener) Performs text completion for a prompt.decode(int[] tokens) Decodes token ids to UTF-8 text.decodeStep(int[] requestIds, int[] lastTokens, int[] positions) One decode step for an active set (same or mixed positions; engine may cohort by position).int[]encodeChat(Message... dialog) Encodes a dialog with the model chat template, leaving the assistant turn open for completion.int[]encodeChat(Message[] dialog, ChatOptions options) Encodes a dialog with optional tool-calling options.voidevict(int requestId) Instant Eviction without radix insert.family()Returns the architecture family label.voidfinish(int requestId, int[] sequenceTokens) Inserts into the radix tree (when enabled) and unbinds the request.generate(int[] prompt, int maxGenLen, double temperature, double topp, boolean logprobs, long seed, GenerationListener listener, BooleanSupplier cancelRequested) Generates a completion from an already-tokenized prompt.voidAdvances pending decode-graph prefetch when the scheduler is idle but KV remains bound (e.g.booleanReturns whether a vision tower is loaded.booleanReturns whether hybrid DeltaNet warm-prefix replay is enabled.booleanReturns whether MTP speculation is enabled.Primary KV cache pool (rank 0 for TP).intReturns the configured maximum sequence length (max-model-len/ context length).model()Returns the underlying language-model façade.name()Returns the model instance / checkpoint name.intReturns the resolved draft depth when speculation is active.intpadToken()Returns the pad token id.params()Hyperparameters from the checkpoint.prefill(int requestId, int[] prompt, int prefixLen) Prefills the unbound suffix of a prompt (activates this request alone).prefillChunk(int requestId, int[] prompt, int from, int to) Prefillsprompt[from, to)(chunked Continuous Batching).prefillMultimodal(int requestId, MultimodalPrompt promptArg, int from, int to) Prefills a multimodal prompt using vision embeds + interleaved mRoPE.intprefixLen(int requestId) Page-aligned matched prefix length for a bound request.processMultimodal(Message... dialog) Processes a multimodal dialog (images/video) into tokens + vision tensors.processMultimodal(Message[] dialog, ChatOptions options) Preprocesses a multimodal dialog with chat options (thinking mode, reasoning effort).voidResets speculative accept-rate and round-timing counters.voidsetNumSpeculativeTokens(int n) Sets draft depth override (<= 0restores the HF/config default).voidsetPrefixReplayEnabled(boolean enabled) Enables Phase-1 hybrid prefix replay: radix KV hits are allowed andwarmPrefix(int, int[], int)rebuilds DeltaNet state over the matched prefix.voidsetPrefixReuseEnabled(boolean enabled) Enables or disables radix prefix reuse on every TP rank's KV pool.voidsetSpeculativeEnabled(boolean enabled) Enables or disables native MTP speculative decoding when MTP weights are loaded.int[][]speculateStep(int[] requestIds, int[] lastTokens, int[] positions, int numDrafts, double[] temperatures, double[] topps) Same asModelExecutor.speculateStep(int[], int[], int[], int, double, double)with per-request sampling parameters, so a cohort whose requests sample differently is still verified in one batched forward.int[][]speculateStep(int[] requestIds, int[] lastTokens, int[] positions, int numDrafts, double temperature, double topp) One speculative MTP round for a uniform draft depth.doubleDraft-token accept rate over completed speculative rounds (accepted / proposed), or0when none yet.doubleMean accepted draft depth per speculative round (0when none).double[]Mean online-round wall-clock breakdown in milliseconds:{draftMs, verifyMs, replayMs, bookkeepingMs}, or all zero before any online round.doubleMean target verify forwards per speculative round (window verify →1).int[]Returns stop / EOS token ids.toString()tryDecode(int[] tokens, boolean skipSpecial) Attempts a streaming decode; returns empty on incomplete UTF-8.Returns the vision args.Returns the VL processor.voidwarmPrefix(int requestId, int[] prompt, int prefixLen) Phase-1 hybrid prefix hit: run a full hybrid forward overprompt[0, prefixLen)so DeltaNet recurrent/conv state matches a cold prefill.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface LanguageModel
chat, generateMethods inherited from interface ModelExecutor
supportsStepApi
-
Constructor Details
-
Qwen
Constructor.- Parameters:
name- model instance / checkpoint name.model- decoder module (single-device).tokenizer- chat / completion tokenizer.params- hyperparameters from the checkpoint.
-
Qwen
public Qwen(String name, QwenModel[] models, TensorParallelGroup tpGroup, Tokenizer tokenizer, QwenModelArgs params) Tensor-parallel constructor.- Parameters:
name- model instance / checkpoint name.models- one decoder shard per TP rank.tpGroup- tensor-parallel group, ornullwhenmodels.length == 1.tokenizer- chat / completion tokenizer.params- hyperparameters from the checkpoint.
-
Qwen
public Qwen(String name, QwenModel[] models, TensorParallelGroup tpGroup, Tokenizer tokenizer, QwenModelArgs params, QwenVisionArgs visionArgs, QwenVlProcessor vlProcessor) Multimodal constructor.- Parameters:
name- model instance / checkpoint name.models- one decoder shard per TP rank.tpGroup- tensor-parallel group, ornull.tokenizer- chat tokenizer.params- text hyperparameters.visionArgs- vision hyperparameters, ornull.vlProcessor- multimodal processor, ornull.
-
-
Method Details
-
isMultimodal
public boolean isMultimodal()Returns whether a vision tower is loaded.- Returns:
truewhen a vision tower is loaded.
-
vlProcessor
Returns the VL processor.- Returns:
- VL processor, or
nullfor text-only.
-
visionArgs
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
toString
-
family
Description copied from interface:LanguageModelReturns the architecture family label.Examples:
meta/llama3,alibaba/qwen3.5. This is not necessarily the public API model id used by serve.- Specified by:
familyin interfaceLanguageModel- Returns:
- the family label string.
-
setPrefixReplayEnabled
public void setPrefixReplayEnabled(boolean enabled) Enables Phase-1 hybrid prefix replay: radix KV hits are allowed andwarmPrefix(int, int[], int)rebuilds DeltaNet state over the matched prefix.- Parameters:
enabled-trueto allow safe hybrid prefix reuse.
-
isPrefixReplayEnabled
public boolean isPrefixReplayEnabled()Returns whether hybrid DeltaNet warm-prefix replay is enabled.- Returns:
- whether hybrid DeltaNet warm-prefix replay is enabled.
-
setSpeculativeEnabled
public void setSpeculativeEnabled(boolean enabled) Enables or disables native MTP speculative decoding when MTP weights are loaded.- Parameters:
enabled-trueto use draft/verify (default when MTP is present).
-
isSpeculativeEnabled
public boolean isSpeculativeEnabled()Returns whether MTP speculation is enabled.- Returns:
- whether MTP speculation is enabled.
-
setNumSpeculativeTokens
public void setNumSpeculativeTokens(int n) Sets draft depth override (<= 0restores the HF/config default).- Parameters:
n- draft token count, capped atQwenModelArgs.MAX_SPECULATIVE_TOKENS.
-
numSpeculativeTokens
public int numSpeculativeTokens()Returns the resolved draft depth when speculation is active.- Returns:
- resolved draft depth when speculation is active, else
0.
-
speculativeAcceptRate
public double speculativeAcceptRate()Draft-token accept rate over completed speculative rounds (accepted / proposed), or0when none yet.- Returns:
- speculative accept rate.
-
speculativeMeanAcceptedDepth
public double speculativeMeanAcceptedDepth()Mean accepted draft depth per speculative round (0when none).- Returns:
- mean accepted draft depth.
-
speculativeMeanTargetForwardsPerRound
public double speculativeMeanTargetForwardsPerRound()Mean target verify forwards per speculative round (window verify →1).- Returns:
- average, or
0when no rounds yet.
-
speculativeMeanRoundTimingMs
public double[] speculativeMeanRoundTimingMs()Mean online-round wall-clock breakdown in milliseconds:{draftMs, verifyMs, replayMs, bookkeepingMs}, or all zero before any online round.- Returns:
- mean per-round timing breakdown in milliseconds.
-
resetSpeculativeMetrics
public void resetSpeculativeMetrics()Resets speculative accept-rate and round-timing counters. -
setPrefixReuseEnabled
public void setPrefixReuseEnabled(boolean enabled) Enables or disables radix prefix reuse on every TP rank's KV pool.- Parameters:
enabled-trueto match/insert prefixes across requests.
-
name
Description copied from interface:LanguageModelReturns the model instance / checkpoint name.- Specified by:
namein interfaceLanguageModel- Returns:
- the instance name (e.g. directory or HF repo leaf name).
-
maxSeqLen
public int maxSeqLen()Description copied from interface:LanguageModelReturns the configured maximum sequence length (max-model-len/ context length).- Specified by:
maxSeqLenin interfaceLanguageModel- Specified by:
maxSeqLenin interfaceModelExecutor- Returns:
- the maximum number of tokens allowed for prompt plus completion.
-
encodeChat
Description copied from interface:LanguageModelEncodes a dialog with the model chat template, leaving the assistant turn open for completion.- Specified by:
encodeChatin interfaceLanguageModel- Parameters:
dialog- ordered conversation turns (system/user/assistant).- Returns:
- prompt token ids ready for
LanguageModel.generate(int[], int, double, double, boolean, long, GenerationListener).
-
encodeChat
Description copied from interface:LanguageModelEncodes a dialog with optional tool-calling options.Default ignores
optionsand delegates toLanguageModel.encodeChat(Message...).- Specified by:
encodeChatin interfaceLanguageModel- Parameters:
dialog- ordered conversation turns.options- chat options; may benull.- Returns:
- prompt token ids.
-
processMultimodal
Processes a multimodal dialog (images/video) into tokens + vision tensors.- Parameters:
dialog- chat turns.- Returns:
- processed multimodal input.
- Throws:
IOException- if media cannot be loaded.
-
processMultimodal
public QwenVlProcessor.ProcessedMultimodal processMultimodal(Message[] dialog, ChatOptions options) throws IOException Preprocesses a multimodal dialog with chat options (thinking mode, reasoning effort).- Parameters:
dialog- the messages.options- chat options; may benull.- Returns:
- the processed prompt and vision tensors.
- Throws:
IOException- if media cannot be read.
-
params
-
build
public static Qwen build(String checkpointDir, int maxBatchSize, int maxSeqLen, byte deviceId) throws IOException Builds a Qwen instance from a HuggingFace checkpoint directory.- Parameters:
checkpointDir- directory containingconfig.jsonand weights.maxBatchSize- maximum batch size for inference.maxSeqLen- maximum sequence length;<= 0uses the config value.deviceId- CUDA device id, or negative for CPU.- Returns:
- a loaded Qwen model.
- Throws:
IOException- if the checkpoint cannot be read.
-
build
public static Qwen build(String checkpointDir, int maxBatchSize, int maxSeqLen, byte deviceId, double memFractionStatic, String kvCacheDtype) throws IOException Builds a Qwen instance from a HuggingFace checkpoint directory.- Parameters:
checkpointDir- directory containingconfig.jsonand weights.maxBatchSize- maximum batch size for inference.maxSeqLen- maximum sequence length;<= 0uses the config value.deviceId- CUDA device id, or negative for CPU.memFractionStatic- static-region fraction of total GPU memory (SGLang-style);<=0keeps test sizing.kvCacheDtype- optional KV dtype override.- Returns:
- a loaded Qwen model.
- Throws:
IOException- if the checkpoint cannot be read.
-
build
public static Qwen build(String checkpointDir, int maxBatchSize, int maxSeqLen, byte deviceId, double memFractionStatic, String kvCacheDtype, ParallelConfig parallel) throws IOException Builds a Qwen instance with optional tensor parallelism.- Parameters:
checkpointDir- directory containingconfig.jsonand weights.maxBatchSize- maximum batch size for inference.maxSeqLen- maximum sequence length;<= 0uses the config value.deviceId- CUDA device id, or negative for CPU.memFractionStatic- static-region fraction of total GPU memory (SGLang-style);<=0keeps test sizing.kvCacheDtype- optional KV dtype override.parallel-ParallelConfig.tensorParallel(byte...)for multi-GPU;ppSizemust be 1.- Returns:
- a loaded Qwen model.
- Throws:
IOException- if the checkpoint cannot be read.
-
build
public static Qwen build(String checkpointDir, int maxBatchSize, int maxSeqLen, byte deviceId, double memFractionStatic, String kvCacheDtype, int pageSize, ParallelConfig parallel) throws IOException Builds a Qwen instance with optional tensor parallelism and KV page size.- Parameters:
checkpointDir- directory containingconfig.jsonand weights.maxBatchSize- maximum batch size for inference.maxSeqLen- maximum sequence length;<= 0uses the config value.deviceId- CUDA device id, or negative for CPU.memFractionStatic- static-region fraction of total GPU memory (SGLang-style);<=0keeps test sizing.kvCacheDtype- optional KV dtype override.pageSize- tokens per radix / KV pool page (>= 1).parallel-ParallelConfig.tensorParallel(byte...)for multi-GPU;ppSizemust be 1.- Returns:
- a loaded Qwen model.
- Throws:
IOException- if the checkpoint cannot be read.
-
build
public static Qwen build(String checkpointDir, int maxBatchSize, int maxSeqLen, byte deviceId, double memFractionStatic, String kvCacheDtype, int pageSize, ParallelConfig parallel, int modelLoaderThreads) throws IOException Builds a Qwen instance with optional tensor parallelism, KV page size, and safetensors loader concurrency.- Parameters:
checkpointDir- directory containingconfig.jsonand weights.maxBatchSize- maximum batch size for inference.maxSeqLen- maximum sequence length;<= 0uses the config value.deviceId- CUDA device id, or negative for CPU.memFractionStatic- static-region fraction of total GPU memory (SGLang-style);<=0keeps test sizing.kvCacheDtype- optional KV dtype override.pageSize- tokens per radix / KV pool page (>= 1).parallel-ParallelConfig.tensorParallel(byte...)for multi-GPU;ppSizemust be 1.modelLoaderThreads- safetensors loader threads;0= auto (SafeTensorsLoaderThreads.resolve(int, int)).- Returns:
- a loaded Qwen model.
- Throws:
IOException- if the checkpoint cannot be read.
-
build
public static Qwen build(String checkpointDir, int maxBatchSize, int maxSeqLen, byte deviceId, double memFractionStatic, String kvCacheDtype, int pageSize, ParallelConfig parallel, int modelLoaderThreads, int speculativeRows, int speculativeDepth) throws IOException Like the overload above, additionally reserving DeltaNet checkpoint memory for batched MTP speculation before the KV pool is sized, so the KV budget accounts for it and a large speculating cohort never has to fall back to plain decode for lack of memory.- Parameters:
checkpointDir- directory containingconfig.jsonand weights.maxBatchSize- maximum batch size for inference.maxSeqLen- maximum sequence length;<= 0uses the config value.deviceId- CUDA device id, or negative for CPU.memFractionStatic- static-region fraction of total GPU memory (SGLang-style);<=0keeps test sizing.kvCacheDtype- optional KV dtype override.pageSize- tokens per radix / KV pool page (>= 1).parallel-ParallelConfig.tensorParallel(byte...)for multi-GPU;ppSizemust be 1.modelLoaderThreads- safetensors loader threads;0= auto (SafeTensorsLoaderThreads.resolve(int, int)).speculativeRows- rows (concurrently speculating requests) to provision;0reserves nothing.speculativeDepth- draft depth to provision for;<= 0uses the model default.- Returns:
- a loaded Qwen model.
- Throws:
IOException- if the checkpoint cannot be read.
-
generate
public ChatCompletion generate(int[] prompt, int maxGenLen, double temperature, double topp, boolean logprobs, long seed, GenerationListener listener, BooleanSupplier cancelRequested) Description copied from interface:LanguageModelGenerates a completion from an already-tokenized prompt.- Specified by:
generatein interfaceLanguageModel- Parameters:
prompt- prompt token id sequence.maxGenLen- maximum number of new tokens to generate (not including the prompt itself).temperature- sampling temperature; higher values increase randomness.topp- nucleus-sampling top-p threshold in(0, 1].logprobs-trueto include per-token log-probabilities in the result.seed- optional RNG seed for deterministic sampling;0means non-deterministic.listener- optional progress callback; may benull.cancelRequested- when non-null and returnstrue, generation stops between decode steps withCancellationException.- Returns:
- the completion for
prompt.
-
complete
public ChatCompletion complete(String prompt, int maxGenLen, double temperature, double topp, boolean logprobs, long seed, GenerationListener listener) Performs text completion for a prompt.- Parameters:
prompt- text prompt.maxGenLen- maximum number of new tokens to generate.temperature- temperature value for controlling randomness in sampling.topp- top-p probability threshold for nucleus sampling.logprobs- flag indicating whether to compute token log probabilities.seed- optional RNG seed to sample deterministically.listener- optional generation progress callback.- Returns:
- the generated text completion.
-
chat
public ChatCompletion chat(Message[] dialog, int maxGenLen, double temperature, double topp, boolean logprobs, long seed, GenerationListener listener, BooleanSupplier cancelRequested) Description copied from interface:LanguageModelGenerates an assistant reply for a dialog.Equivalent to
LanguageModel.encodeChat(Message...)followed byLanguageModel.generate(int[], int, double, double, boolean, long, GenerationListener).- Specified by:
chatin interfaceLanguageModel- Parameters:
dialog- ordered conversation turns.maxGenLen- maximum number of new tokens to generate.temperature- sampling temperature; higher values increase randomness.topp- nucleus-sampling top-p threshold in(0, 1].logprobs-trueto include per-token log-probabilities in the result.seed- optional RNG seed for deterministic sampling;0means non-deterministic.listener- optional progress callback; may benull.cancelRequested- cooperative cancel flag; may benull.- Returns:
- the completion for
dialog.
-
model
Description copied from interface:ModelExecutorReturns the underlying language-model façade.- Specified by:
modelin interfaceModelExecutor- Returns:
- language model.
-
kvCachePool
Description copied from interface:ModelExecutorPrimary KV cache pool (rank 0 for TP). May benullonly for models without full-attention layers.- Specified by:
kvCachePoolin interfaceModelExecutor- Returns:
- KV cache pool, or
null.
-
padToken
public int padToken()Description copied from interface:ModelExecutorReturns the pad token id.- Specified by:
padTokenin interfaceModelExecutor- Returns:
- pad token id.
-
stopTokens
public int[] stopTokens()Description copied from interface:ModelExecutorReturns stop / EOS token ids.- Specified by:
stopTokensin interfaceModelExecutor- Returns:
- stop token ids.
-
decode
Description copied from interface:ModelExecutorDecodes token ids to UTF-8 text.- Specified by:
decodein interfaceModelExecutor- Parameters:
tokens- token ids.- Returns:
- decoded text.
-
tryDecode
Description copied from interface:ModelExecutorAttempts a streaming decode; returns empty on incomplete UTF-8.- Specified by:
tryDecodein interfaceModelExecutor- Parameters:
tokens- token ids.skipSpecial- whether to skip special tokens.- Returns:
- decoded text, or empty on incomplete UTF-8.
- Throws:
CharacterCodingException- when the sequence is incomplete.
-
bind
public int bind(int[] prompt, int totalCapacity) Description copied from interface:ModelExecutorBinds one request into the KV pool (multi-request safe).- Specified by:
bindin interfaceModelExecutor- Parameters:
prompt- prompt token ids.totalCapacity- desired slots (prompt + generation).- Returns:
- request id (
> 0).
-
prefixLen
public int prefixLen(int requestId) Description copied from interface:ModelExecutorPage-aligned matched prefix length for a bound request.- Specified by:
prefixLenin interfaceModelExecutor- Parameters:
requestId- id fromModelExecutor.bind(int[], int).- Returns:
- prefix length (
>= 0).
-
prefillMultimodal
Description copied from interface:ModelExecutorPrefills a multimodal prompt using vision embeds + interleaved mRoPE. Default throws; Qwen and MiniMax override.- Specified by:
prefillMultimodalin interfaceModelExecutor- Parameters:
requestId- request id.promptArg- preprocess result.from- inclusive start (normally 0; prefix reuse disabled for VL).to- exclusive end.- Returns:
- logits when
to == inputIds.length, else null.
-
prefill
Description copied from interface:ModelExecutorPrefills the unbound suffix of a prompt (activates this request alone).- Specified by:
prefillin interfaceModelExecutor- Parameters:
requestId- request id.prompt- full prompt tokens.prefixLen- cached prefix to skip (fromModelExecutor.prefixLen(int)).- Returns:
- last-position logits shaped
[1, vocab](caller owns).
-
warmPrefix
public void warmPrefix(int requestId, int[] prompt, int prefixLen) Phase-1 hybrid prefix hit: run a full hybrid forward overprompt[0, prefixLen)so DeltaNet recurrent/conv state matches a cold prefill. Shared radix KV pages are rewritten with equivalent values.Skipping full-attention residuals here would be incorrect — DeltaNet inputs depend on the residual stream after attention blocks.
- Specified by:
warmPrefixin interfaceModelExecutor- Parameters:
requestId- request id fromModelExecutor.bind(int[], int).prompt- full prompt tokens.prefixLen- page-aligned matched prefix (>= 0).
-
prefillChunk
Description copied from interface:ModelExecutorPrefillsprompt[from, to)(chunked Continuous Batching). Returns last-token logits only whento == prompt.length.- Specified by:
prefillChunkin interfaceModelExecutor- Parameters:
requestId- request id.prompt- full prompt tokens.from- inclusive start position in the prompt.to- exclusive end position.- Returns:
- logits
[1, vocab]when the prompt is fully prefilled; otherwisenull.
-
speculateStep
public int[][] speculateStep(int[] requestIds, int[] lastTokens, int[] positions, int numDrafts, double[] temperatures, double[] topps) Description copied from interface:ModelExecutorSame asModelExecutor.speculateStep(int[], int[], int[], int, double, double)with per-request sampling parameters, so a cohort whose requests sample differently is still verified in one batched forward. The default delegates to the scalar overload when every request shares the same parameters and otherwise runs the requests one at a time.- Specified by:
speculateStepin interfaceModelExecutor- Parameters:
requestIds- active KV request ids (order = batch).lastTokens- last committed token per request.positions- absolute position oflastTokens[i](write of next is+1).numDrafts- draft depth (same for every request in this call).temperatures- per-request sampling temperature (verify).topps- per-request nucleus top-p (verify).- Returns:
- accepted token ids per request (each length
>= 1; caller owns arrays).
-
speculateStep
public int[][] speculateStep(int[] requestIds, int[] lastTokens, int[] positions, int numDrafts, double temperature, double topp) Description copied from interface:ModelExecutorOne speculative MTP round for a uniform draft depth.Default throws; Qwen overrides when MTP weights are loaded.
- Specified by:
speculateStepin interfaceModelExecutor- Parameters:
requestIds- active KV request ids (order = batch).lastTokens- last committed token per request.positions- absolute position oflastTokens[i](write of next is+1).numDrafts- draft depth (same for every request in this call).temperature- sampling temperature (verify).topp- nucleus top-p (verify).- Returns:
- accepted token ids per request (each length
>= 1; caller owns arrays).
-
decodeStep
Description copied from interface:ModelExecutorOne decode step for an active set (same or mixed positions; engine may cohort by position). Tokens are[B]last tokens; positions are the write index for each row.- Specified by:
decodeStepin interfaceModelExecutor- Parameters:
requestIds- active KV request ids (order = batch).lastTokens- token id per request.positions- absolute position per request.- Returns:
- logits
[B, vocab](caller owns).
-
finish
public void finish(int requestId, int[] sequenceTokens) Description copied from interface:ModelExecutorInserts into the radix tree (when enabled) and unbinds the request.- Specified by:
finishin interfaceModelExecutor- Parameters:
requestId- request id.sequenceTokens- prompt + completion (no pad).
-
evict
public void evict(int requestId) Description copied from interface:ModelExecutorInstant Eviction without radix insert.- Specified by:
evictin interfaceModelExecutor- Parameters:
requestId- request id.
-
idleDecodeGraphPrefetch
public void idleDecodeGraphPrefetch()Description copied from interface:ModelExecutorAdvances pending decode-graph prefetch when the scheduler is idle but KV remains bound (e.g. between continuous-batching waves).- Specified by:
idleDecodeGraphPrefetchin interfaceModelExecutor
-