|
|
| 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.
|
| virtual std::string | toString () const =0 |
| | Human-readable summary of this model's configuration.
|
| void | train () |
| | Run the training loop for this model.
|
|
| | 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 int32_t | eosToken () const noexcept=0 |
| 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 |
| virtual dim_t | maxSequenceLength () const noexcept=0 |
| virtual GenerateStatus | onGenerating (std::span< const int32_t > prompt_tokens, const std::function< void(int32_t)> &on_token, const GenerateParams ¶ms, std::stop_token stop)=0 |
| | Prefill + decode implementation hook.
|
| int32_t | sampleNext (const TensorType &logits, TokenTensor &token_out, const SamplingParams ¶ms) |
| | Sample the next token from a logits row on the device.
|
|
virtual std::unordered_set< int32_t > | stopTokens () const |
| virtual dim_t | vocabSize () const noexcept=0 |
| | Model (std::unique_ptr< NetworkType > network, RuntimeMode runtime_mode) |
| | Construct with a fully built network and runtime mode.
|
| virtual void | onTraining ()=0 |
| | Training loop hook – derived class owns the implementation.
|
Watch activations flowing through matching components on matching passes.
The consumer's door onto observation. Every component already publishes on every inference pass, but publication is gated per component and the network is behind a protected accessor, so without this a caller cannot reach in – which is how the first consumer ended up with a purpose-built accessor bolted onto this class instead of using the machinery that was already there.
pattern is a component path with * matching any run of characters. What the paths are is answerable: see componentPaths().
model->observe( "*.lm_head", ComputePassMask::inference(),
[]( std::string_view path,
ComputePass pass, std::string_view stage,
{
} );
ComputePass
The compute entry point that produced an observed value.
Definition Observation.ixx:29
Abstract interface providing essential tensor information and data access.
Definition ITensor.ixx:40
The tensor handed to the sink is borrowed for the duration of the call and ordered on the publishing component's stream, not valid on the host. Publication never synchronizes, because synchronizing is the clearest way for a probe to change what it is observing.
- Returns
- How many components matched. Check it – zero means nothing will publish, and downstream that is indistinguishable from a clean run.
| virtual GenerateStatus Mila::Dnn::LanguageModel< TDeviceType, TPrecision >::onGenerating |
( |
std::span< const int32_t > | prompt_tokens, |
|
|
const std::function< void(int32_t)> & | on_token, |
|
|
const GenerateParams & | params, |
|
|
std::stop_token | stop ) |
|
protectedpure virtual |
Write this model's live weights as a safetensors weights file.
The inverse of load: what this writes is what that reads. Weights go out as they currently sit on the device, so a model loaded under FP4 or FP8 produces PRE-QUANTIZED weights – packed storage plus its scale companions. That is the point of the operation: quantization is a load-time policy, so the quantized bytes exist nowhere until a model has been built with one.
The source weights file's metadata is written back verbatim, so the result loads by the same path that loaded the original and is readable by any safetensors reader without Mila.
Family-agnostic by construction: the tensor vocabulary comes from the network's own flat-save traversal, so a family is covered as soon as every composite that owns a parameter drives both halves of it. A composite that only recurses and silently drops its own tensors is the failure this cannot see – the export tool's source reconciliation is what catches that.
- Parameters
-
| path | Destination weights file; parent directories are created. |
- Exceptions
-
| std::runtime_error | if the model carries no weights metadata (it was reconstructed from a checkpoint), or if the file cannot be written. |