nvalchemi.gen.GeneratingFunction#
- class nvalchemi.gen.GeneratingFunction(*args, **kwargs)[source]#
Callable that encapsulates a family-specific generation strategy.
A
GeneratingFunctionowns everything generation needs – including the model, when there is one (held as a closure or an attribute of a callable object) – samples from it, and returns the generated artifact.Conditioning may live inside the function, or as a
conditionattribute the driver calls before generation (see below); with neither, the inputs pass through untouched as the first positional argument.num_samplessemantics are the function’s own (per-conditioning-entry draws vs an unconditional total); the driver passes itsnum_samplesstraight through.rngisNoneunless the driver has aseed, a session, or a per-callrng=– handleNone(torch sampling ops accept it). Outside a session the resolved RNG is CPU-resident even when generating on CUDA; inside a session it lives on the resolved device. When you draw on a device, make sure the generator matches it (e.g.torch.randn(..., generator=rng, device=...)).Return a
Batch: that is the output contract. The driver fires theAFTER_GENERATEhooks on it, validates its device and declaredoutputs, and pipelines compose it (including driving dynamics on it). Any other container is a fallback with real losses:sample()passes it through untouched, theAFTER_GENERATEhooks are skipped, and it cannot feed dynamics stages. Inside the function, aTensorDictsurvivestorch.compilewhere arbitrary containers graph-break undercompile_generate; convert it to aBatchbefore returning. Library-native sampling loops (e.g. PhysicsNeMo diffusion samplers) plug in through a thin adapter with this signature.Optional attributes. A callable object (rather than a plain function) may carry attributes the
AtomisticGeneratorreads as defaults when the driver does not set them explicitly:condition– aConditionFunctionmapping the call’s raw inputs to the conditioned value the function is then called with (e.g. tiling a conditioningBatchso each graph getsnum_samplesdraws). The driver runs it between theBEFORE_CONDITIONandAFTER_CONDITIONdispatches, which fire only when a condition step is provided; an explicit drivercondition_functakes precedence over this attribute. There is no default condition: functions implement their own per use case, binding any extra context in their closure.device– atorch.device(or parseable device string), used when the driver’sdeviceis unset.required_inputs/outputs– batch-field declarations, used when the driver does not pass them at construction.