|
|
| QwenModel (const QwenModel &)=delete |
|
| QwenModel (QwenModel &&)=default |
|
dim_t | contextLength () const noexcept |
| | Deployment context length: the KV-cache depth the network was built with.
|
|
const QwenModelConfig & | getModelConfig () const noexcept |
| | Deployment configuration this model was loaded with.
|
|
const QwenConfig & | getNetworkConfig () const noexcept |
| | Architecture/network configuration (read from the checkpoint metadata).
|
| dim_t | maxSequenceLength () const noexcept override |
|
QwenModel & | operator= (const QwenModel &)=delete |
|
QwenModel & | operator= (QwenModel &&)=default |
| SequenceLogLikelihood | scoreTokens (const std::vector< int32_t > &tokens) |
| | Teacher-forced log-likelihood of a token sequence – the perplexity path.
|
| bool | supportsPromptPrefixReuse () const noexcept |
| | False, always: this stack cannot reuse a prompt prefix.
|
| std::string | toString () const override |
| | Human-readable summary of this model's configuration.
|
| dim_t | vocabSize () const noexcept override |
|
| LanguageModel (const LanguageModel &)=delete |
|
| LanguageModel (LanguageModel &&)=default |
|
std::vector< std::string > | componentPaths () const |
| | Every observable component path, for choosing a pattern or diagnosing a zero.
|
| GenerateStatus | generate (std::span< const int32_t > prompt_tokens, const std::function< void(int32_t)> &on_token, const GenerateParams ¶ms={}, std::stop_token stop={}) |
| | Generate tokens from a prompt, streaming each through on_token.
|
| size_t | observe (std::string_view pattern, Compute::ComputePassMask passes, Compute::ActivationObserver sink) |
| | Watch activations flowing through matching components on matching passes.
|
|
LanguageModel & | operator= (const LanguageModel &)=delete |
|
LanguageModel & | operator= (LanguageModel &&)=default |
| void | save (const std::filesystem::path &path) const |
| | Write this model's live weights as a safetensors weights file.
|
| void | seedSampler (uint64_t seed) |
| | Seed the sampler's RNG for reproducible generation.
|
|
void | stopObserving () |
| | Detach every observer and clear the sink. A probe that outlives its question costs.
|
| std::string | weightQuantizationScheme () const |
| | The scheme name save records for these weights, e.g.
|
|
| Model (const Model &)=delete |
|
| Model (Model &&)=default |
|
DeviceId | getDeviceId () const noexcept |
| | The device this model runs on.
|
|
MemoryStats | getMemoryStats () const |
| | Current memory allocation breakdown for this model.
|
| RuntimeMode | getRuntimeMode () const noexcept |
| | The runtime mode this model was constructed for.
|
| bool | isEval () const noexcept |
| | True if this model is currently in eval sub-state.
|
| bool | isInferenceMode () const noexcept |
| | True if this model was constructed for inference.
|
| bool | isTrainingMode () const noexcept |
| | True if this model was constructed for training.
|
|
Model & | operator= (const Model &)=delete |
|
Model & | operator= (Model &&)=default |
| void | setEval (bool eval) |
| | Toggle eval sub-state for this model.
|
| void | train () |
| | Run the training loop for this model.
|
|
| static QwenConfig | configFromMetadata (const WeightsMetadata &metadata) |
| | The network geometry an artifact's metadata declares.
|
| static DeploymentFootprint | getDeploymentFootprint (const std::filesystem::path &path, const QwenModelConfig &model_config, DeviceId device_id=DeviceId{ TDeviceType, 0 }) |
| | The same prediction, plus how this deployment would chunk its prefill.
|
| static MemoryStats | getRequiredMemory (const std::filesystem::path &path, const QwenModelConfig &model_config, DeviceId device_id=DeviceId{ TDeviceType, 0 }) |
| | What loading this checkpoint at this context length would cost in VRAM.
|
| static std::unique_ptr< QwenModel< TDeviceType, TPrecision > > | load (const std::filesystem::path &path, const QwenModelConfig &model_config, DeviceId device_id=DeviceId{ TDeviceType, 0 }) |
| | Load Qwen 3.8 from a Mila weights file.
|
|
| int32_t | eosToken () const noexcept override |
| GenerateStatus | onGenerating (std::span< const int32_t > prompt_tokens, const std::function< void(int32_t)> &on_token, const GenerateParams ¶ms, std::stop_token stop) override |
| | Prefill + decode implementation hook.
|
| void | onTraining () override |
| | Training loop hook – derived class owns the implementation.
|
| std::unordered_set< int32_t > | stopTokens () const override |
| | LanguageModel (std::unique_ptr< LanguageModelNetwork< TDeviceType, TPrecision > > network, RuntimeMode runtime_mode, Serialization::WeightsMetadata source_metadata={}, WeightQuantization weight_quantization=WeightQuantization::None, int fp4_group_size=128) |
| int32_t | awaitSampledToken () |
| | Block until the last enqueueSampleNext()'s token id is host-visible.
|
| void | enqueueSampleNext (const TensorType &logits, TokenTensor &token_out, const SamplingParams ¶ms) |
| | Enqueue a sampling step without waiting for the host readback.
|
| virtual float | finalLogitSoftcap () const noexcept |
| | Optional final-logit softcap the sampler applies (0 disables).
|
|
const LanguageModelNetwork< TDeviceType, TPrecision > & | getNetwork () const noexcept |
|
LanguageModelNetwork< TDeviceType, TPrecision > & | getNetwork () noexcept |
| int32_t | sampleNext (const TensorType &logits, TokenTensor &token_out, const SamplingParams ¶ms) |
| | Sample the next token from a logits row on the device.
|
| | Model (std::unique_ptr< NetworkType > network, RuntimeMode runtime_mode) |
| | Construct with a fully built network and runtime mode.
|
template<
DeviceType TDeviceType,
TensorDataType TPrecision>
requires PrecisionSupportedOnDevice<TPrecision, TDeviceType>
class Mila::Dnn::QwenModel< TDeviceType, TPrecision >
Qwen 3.8 compatible inference model.
Owns a loaded, built QwenTransformer and drives the prefill + decode loop. Construction is only possible via load().
Thread safety: not thread-safe; external synchronization required if shared.
Teacher-forced log-likelihood of a token sequence – the perplexity path.
Reports the probability the model assigned to each token given the ones before it. Nothing is sampled, so the result depends only on the model and the text, which is what makes it comparable between two quantizations of the same weights.
Perplexity over a corpus is exp( -total_log_probability / scored_positions ) after summing several of these. Segment the corpus and sum, rather than averaging each segment, or a short segment weighs as much as a long one.
Needs a deployment built with withLanguageModelHeadPositions() above 1 to run at a sensible rate; at the default of 1 it works and costs one head pass per token.
- Parameters
-
| tokens | A single sequence, at least 2 tokens, no longer than contextLength(). |