Inference-time model_config overrides with an allowlist of sampling-only keys #87
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Some config keys only affect sampling, not model construction or data preprocessing, so they could legitimately be changed at inference time on an already-trained checkpoint — without retraining. Today there is no way to do that:
giant predict/giant rolloutrebuild the models fromckpt["model_config"](giant/checkpoint_io.py:191,build_models), and nothing lets a caller alter that dict.Concrete motivating case: flipping
stage2_model.n_sec.stop_samplingbetween"greedy"and"sample"for a rollout comparison. It is carried into a plain attribute onStage2Autoregressive(giant/model/builders.py:141,giant/model/models.py:517) and read only at sample time (giant/sample.py:348). It touches nostate_dictkey and no shape.giant/model/summary.py:143already names this class of key explicitly.Proposal
Add a
config_overrides: dict | Noneparameter toload_for_inferencethat deep-merges dotted paths intomodel_cfgbeforebuild_models, validated against an explicit allowlist of inference-safe paths.The allowlist is the essential part. Without it a typo or a shape-changing key (
hidden_dim) surfaces as an opaqueload_state_dictsize-mismatch traceback; with it, it raisesCheckpointCompatibilityErrorwith the same wording style as the module's other failures.Criteria for a key to be inference-safe:
Initial allowlist candidates:
stage2_model.n_sec.stop_sampling(andn_sec.sampling, once the companionmode="head"sampling issue lands)stage1_model.ddpm.n_steps/stage2_model.ddpm.n_steps(already surfaced asstage{1,2}_ddpm_stepsonInferenceContext)stage2_model.particle_type.other_policy(already surfaced asother_policy)stage1_model.router.temperature/stage2_model.router.temperature(EnergyRouter.temperature)Rejected by design: anything shape-bearing (
hidden_dim,n_layers,k_max,emb_dim,n_experts), anything conditioning-mode-bearing (conditioning.*.type,particle_type.target), and all of[train].Both
predictandrolloutget the capability for free from the singleload_for_inferencechange. Preferred over the alternative of a post-loadsetattrin the CLI, which scatters override logic and does not generalize.Surface
--set key=value(or per-key flags) ongiant predict/giant rolloutgiant rolloutYAML sidecar should record the overrides actually applied, so the analysis pipeline can tell two rollouts of the same checkpoint apartgiant model summaryoutput where relevantAcceptance
load_for_inference(..., config_overrides=...)merges intomodel_cfgbeforebuild_modelsCheckpointCompatibilityError, never aload_state_dictmismatchgiant/config.py's existing per-key checks where they existpredictandrollout; applied overrides recorded in the rollout YAML