|
| | BuildContext () |
| | Default constructor — sentinel value for pre-build state.
|
| | BuildContext (shape_t input_shape, RuntimeMode runtime_mode, bool initialize_parameters=true) |
| | Construct from all six concerns explicitly.
|
| int64_t | getPrefillSize () const noexcept |
| | Number of tokens processed per prefill pass.
|
| RuntimeMode | getRuntimeMode () const noexcept |
| | Return a copy of this context with a different quantization config.
|
| const shape_t & | inputShape () const noexcept |
| | The full input shape this component receives.
|
| bool | isInferenceMode () const noexcept |
| | True if output buffers should be allocated at T=1.
|
| bool | isTrainingMode () const noexcept |
| | True if output buffers should be allocated at full input shape sequence length with gradient buffers.
|
| bool | shouldInitializeParameters () const noexcept |
| | True if components should initialize parameter values after allocation.
|
| BuildContext | withPrefillSize (int64_t prefill_size) const |
| | Return a copy of this context with a different prefill size.
|
| BuildContext | withShape (shape_t new_shape) const |
| | Return a copy of this context with a different input shape.
|
Build-time context for Component::build().
Carries six orthogonal concerns down the Component hierarchy:
- Input shape — the full input shape the component receives. Used for parameter sizing, output buffer allocation, and build-time validation against component config.
RuntimeMode — allocation policy governing output buffer sizing and gradient buffer allocation.
Inference — T=1 decode path output buffers. Training — full sequence output buffers, gradient buffers allocated.
- Parameter initialization — whether components should initialize parameter tensors after allocation. Set to false when building for a pretrained weight load to avoid computing initializers (Xavier, normal, zeros) that are immediately overwritten by loadParameter(). Defaults to true (training from scratch).
Caller responsibility
The Network or Transformer constructing BuildContext is responsible for providing the correct full input shape for each child component. Each component validates this shape against its own config in onBuilding().
Threading
Not synchronized. Used only during the single-threaded build phase.
- Examples
- /__w/Mila/Mila/Mila/Src/Dnn/Components/Activations/Gelu/Gelu.ixx, and /__w/Mila/Mila/Mila/Src/Dnn/Components/Normalization/Softmax.ixx.