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 every GenerationStage and the AtomisticGenerator re-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_GENERATE hooks see it here), None on the raw path. At call start it holds inputs when they are a Batch (None otherwise). The raw sample in whatever container the generating function produced lives on sample, 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, or None for unconditional generation. When a condition step is provided for the call, the driver runs it between the BEFORE_CONDITION and AFTER_CONDITION dispatches and stores the conditioned value back here, so from AFTER_CONDITION on 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_CONDITION and consumed at AFTER_GENERATE).

Type:

dict[str, Any]

step_count#

Which generation call this is within a stream; 0 for 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 Batch path when it is a Batch (and AFTER_GENERATE hooks see it as ctx.batch there), 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. DeduplicateHook aligns 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. None until a hook records a mask.

Type:

torch.Tensor | None