|
|
| GemmaModel (const GemmaModel &)=delete |
|
| GemmaModel (GemmaModel &&)=default |
|
dim_t | contextLength () const noexcept |
| | Deployment context length: the KV-cache depth the network was built with.
|
|
const GemmaModelConfig & | getModelConfig () const noexcept |
| | Deployment configuration (context length, weight-quant, kv-compression) this model was loaded with.
|
|
const GemmaConfig & | getNetworkConfig () const noexcept |
| | Architecture/network configuration (read from the checkpoint metadata).
|
|
GemmaModel & | operator= (const GemmaModel &)=delete |
|
GemmaModel & | operator= (GemmaModel &&)=default |
| std::string | toString () const override |
| | Human-readable summary of this model's configuration.
|
|
| 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 GemmaConfig | configFromMetadata (const WeightsMetadata &metadata) |
| | The network geometry a load of this file builds.
|
| static DeploymentFootprint | getDeploymentFootprint (const std::filesystem::path &path, const GemmaModelConfig &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 GemmaModelConfig &model_config, DeviceId device_id=DeviceId{ TDeviceType, 0 }) |
| | What loading this checkpoint at this context length would cost in VRAM.
|
| static std::unique_ptr< GemmaModel< TDeviceType, TPrecision > > | load (const std::filesystem::path &path, const GemmaModelConfig &model_config, DeviceId device_id=DeviceId{ TDeviceType, 0 }) |
| | Load Gemma 4 from a Mila weights file.
|
|
| dim_t | maxSequenceLength () 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.
|
| dim_t | vocabSize () const noexcept 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.
|
|
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::GemmaModel< TDeviceType, TPrecision >
Gemma 4 compatible inference model.
Owns a loaded, built GemmaTransformer and drives the prefill + KV-cache decode two-phase generation loop. Construction is only possible via load(); the network is always built, weights-loaded, and in inference mode when generation runs.
Thread safety: not thread-safe; external synchronization required if shared.
The same prediction, plus how this deployment would chunk its prefill.
One graph construction answers both, because they are two readings of the same arithmetic – the chunk is resolved on the way to sizing the activation workspaces getRequiredMemory reports, and was previously discarded there.
The second half is what a caller choosing a context length needs and memory alone cannot tell it: the largest context that fits can be one where the chunk has walked down to its floor, because a longer context leaves less of the free memory for the chunk. See Specifications/MemoryFootprint.md section 11.
- Exceptions
-
| std::invalid_argument | on device type mismatch or zero context length. |
| std::runtime_error | on an unreadable artifact or unsupported quantization. |
What loading this checkpoint at this context length would cost in VRAM.
Reads the artifact header for geometry and constructs the graph, then reports what build() would allocate – without building it, without reading a weight, and therefore without needing the device to have room. Answers before a multi-gigabyte download and for hardware the caller does not own.
Returns measurements only. Whether a given headroom is too tight is a deployment policy and belongs to the adaptor, not here; on Windows in particular WDDM oversubscribes rather than failing, so "fits" is not a property the runtime can decide. See Specifications/MemoryFootprint.md.
- Exceptions
-
| std::invalid_argument | on device type mismatch or zero context length. |
| std::runtime_error | on an unreadable artifact or unsupported quantization. |
|
|
inlineoverrideprotectedvirtual |
Training loop hook – derived class owns the implementation.
Called by train() after precondition enforcement. The derived class has total control over data loading, optimizer construction, loss computation, backward pass, checkpointing, and sampling.
Pure virtual – a model declaring RuntimeMode::Training must provide a training loop.
Implements Mila::Dnn::Model< TDeviceType, TPrecision >.