nvalchemi.gen.GenerationContext#
- class nvalchemi.gen.GenerationContext(*, batch=None, model=None, global_rank=0, workflow=None, inputs=None, intermediates=<factory>, step_count=0, sample=None, accepted_mask=None)[source]#
Context object passed to generation hooks.
One context instance spans a single
sample()call: the same object is dispatched at everyGenerationStageand theAtomisticGeneratorre-reads it after each dispatch, so hooks mutate generation state by replacing context fields (ctx.batch = ctx.batch[keep]), not by editing in place.- Parameters:
batch (Batch | None)
model (BaseModelMixin | None)
global_rank (int)
workflow (Any)
inputs (Any)
intermediates (dict[str, Any])
step_count (int)
sample (Any)
accepted_mask (torch.Tensor | None)
- batch#
The generated batch on the contract path: set when the generating function returns a
Batch(AFTER_GENERATEhooks see it here),Noneon the raw path. At call start it holdsinputswhen they are aBatch(Noneotherwise). The raw sample in whatever container the generating function produced lives onsample, not here.- Type:
Batch | None
- inputs#
The input for the current call: at call start, exactly what was passed to
sample(): a tensor container (Batch,TensorDict, …) with text or other raw modalities already encoded, orNonefor unconditional generation. When a condition step is provided for the call, the driver runs it between theBEFORE_CONDITIONandAFTER_CONDITIONdispatches and stores the conditioned value back here, so fromAFTER_CONDITIONon this is what the generating function is called with; with no condition step it stays the raw call input.- Type:
Any
- intermediates#
Scratch space for hook-to-hook state within one call (e.g. an embedding computed at
AFTER_CONDITIONand consumed atAFTER_GENERATE).- Type:
dict[str, Any]
- step_count#
Which generation call this is within a stream;
0for a one-shot call. Drives hook frequency gating.- Type:
int
- sample#
The raw sample for this call, set when the generating function returns. The driver returns it through the
Batchpath when it is aBatch(andAFTER_GENERATEhooks see it asctx.batchthere), as-is otherwise. This is the hot path: the sample should be GPU tensors; it may be any structure the function emits.- Type:
Any
- accepted_mask#
Boolean acceptance mask written by a hook. The writing hook defines which rows it refers to; there is no universal alignment with the original call’s candidates.
DeduplicateHookaligns its mask with the Batch entering that hook and replaces any earlier mask. The generation driver does not use this field to filter, stop, or resample.Noneuntil a hook records a mask.- Type:
torch.Tensor | None