Skip to content

fix(action): default policy servers to deterministic cuDNN across restarts - #459

Open
kane-vln wants to merge 2 commits into
mainfrom
kane-vln/bug-policy-inference-isnt-reproducible-across-re
Open

kane-vln wants to merge 2 commits into
mainfrom
kane-vln/bug-policy-inference-isnt-reproducible-across-re

Conversation

@kane-vln

@kane-vln kane-vln commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #448

With identical observation, prompt, and fixed seed (--seed 0 --deterministic-seed), Action policy server inference varied across OS process restarts because Wan2.2 VAE observation encoding (WanVAE_ in bfloat16) ran with torch.backends.cudnn.benchmark = True and torch.backends.cudnn.deterministic = False. Timing noise on first convolution invocation per process picked between nearly-tied cuDNN algorithms with different bfloat16 reduction orders, perturbing the observation latent (vae2llm input) and amplifying across denoising steps into visible open-loop action chunk differences.

Changes

  • Inference setup & model loaders (cosmos_framework/inference/common/args.py, cosmos_framework/inference/model.py, cosmos_framework/inference/inference.py):
    • Add tri-state cudnn_deterministic: bool | None = None to SetupOverrides / SetupArgs:
      • None preserves existing non-policy inference behavior (cudnn.deterministic=False, cudnn.benchmark=True on HF / frozen-config DCP, and unchanged trainer.cudnn on module-config DCP).
      • True / False configures both Cosmos3OmniModel.from_pretrained_dcp(..., cudnn_deterministic=...) and module-config DCP load_model_from_checkpoint (trainer.cudnn.deterministic / trainer.cudnn.benchmark appended after experiment_overrides).
    • Normalize bracketed experiment_overrides via _normalize_dotlist_overrides(...) in ConfigOverrides._build_config(), CheckpointOverrides._build_checkpoint(), OmniInference._create(), and the LIBERO/RoboCasa _load_introspection_config_dict() fallback.
  • Action policy servers (cosmos_framework/scripts/action_policy_server_{robolab,libero,robocasa}.py):
    • Default cudnn_deterministic: bool = True (--cudnn-deterministic / --no-cudnn-deterministic via Tyro) across all three Action policy server entrypoints.
    • Record and log effective post-load torch.backends.cudnn.{deterministic,benchmark} flags at startup (and in /info on LIBERO/RoboCasa).
  • Documentation & tests:
    • Document --cudnn-deterministic / --no-cudnn-deterministic alongside --seed / --deterministic-seed and persistent TORCHINDUCTOR_CACHE_DIR compiler-cache expectations in docs/action_policy_droid_server.md.
    • Add L0 CPU tests (cosmos_framework/inference/args_test.py, cosmos_framework/inference/model_test.py, cosmos_framework/scripts/action_policy_server_robolab_test.py) covering CLI flags, GPU-less host isolation, cuDNN flag restoration, HF / frozen-DCP / real Hydra action_policy_droid_nano module-DCP override precedence, and bracketed overrides.
    • Add L0 1-GPU cross-process WanVAE_ (bfloat16) determinism regression test (cosmos_framework/scripts/action_policy_server_cudnn_gpu_test.py).

Verification

  • Lint & docs pre-commit:
    • ruff check & ruff format --check on all touched Python files: passed
    • rumdl check --fix & markdown-toc-creator on docs/action_policy_droid_server.md: passed
    • python -m cosmos_framework.scripts.export_schemas: passed
  • CPU unit & Hydra composition tests (both GPU-hidden and GPU-visible):
    • COSMOS_TRAINING=0 & COSMOS_TRAINING=1 pytest across args_test.py, model_test.py, video_guardrail_test.py, action_policy_server_robolab_test.py, and --num-gpus=0 deselection of action_policy_server_cudnn_gpu_test.py: passed
  • GPU cross-process WanVAE_ (bfloat16) determinism test:
    • Local GB10 (CUDA 13.0, cuDNN 9.20.0.48, 12 fresh processes before/after + pytest --levels=0 --num-gpus=1): 9/12 unique latent SHA-256 hashes under benchmark=True (43.36 ms avg) -> 1/12 unique SHA-256 hash across all 12 restarts under deterministic=True, benchmark=False (44.01 ms avg)
  • Full-checkpoint GB200 end-to-end acceptance (CUDA 13.3, cuDNN 9.23.0, 4x GB200, Slurm Job 3715710 + diagnostic Job 3715521):
    • Single-rank HF (Cosmos3-Nano-Policy-DROID, 3 fresh OS processes sharing persistent TORCHINDUCTOR_CACHE_DIR, default cudnn_deterministic=True, seed=0, deterministic_seed=True): post-load cudnn_deterministic=True, cudnn_benchmark=False; [32, 8] float32 action chunks bit-identical across all 3 restarts (np.array_equal, max_abs_diff = 0.0, SHA-256 6b5884233d335a2ff31ad0b0b27367cc0439c06a7abb624f80dcbe846348b297; 12.65s vs 13.24s with --no-cudnn-deterministic). Separate diagnostic harness runs with OmniSetupOverrides(..., use_torch_compile=False) also matched across fresh OS processes (max_abs_diff = 0.0, SHA-256 f111b58efc312b88), and an in-process torch.use_deterministic_algorithms(True, warn_only=True) diagnostic emitted zero nondeterministic op warnings.
    • Two-rank --cfg-parallel HF (Cosmos3-Nano-Policy-DROID, 2 fresh torchrun --nproc-per-node=2 launches sharing persistent TORCHINDUCTOR_CACHE_DIR): post-load cudnn_deterministic=True, cudnn_benchmark=False on both rank 0 and rank 1; clean worker_loop() + shutdown_worker(); [32, 8] float32 action chunks bit-identical across both restarts (np.array_equal, max_abs_diff = 0.0, SHA-256 90d1f2273faa368c1b5dda2bd493a2e4d0039d55ab9da08dd850984efd93ef7b).
    • Module-config DCP (Cosmos3-Nano-dcp + experiment=action_policy_droid_nano + bracketed experiment_overrides, 2 fresh OS processes sharing persistent TORCHINDUCTOR_CACHE_DIR + opt-out): default cudnn_deterministic=True verified both live and in saved config.yaml (trainer.cudnn: {deterministic: true, benchmark: false}), [32, 8] float32 action chunks bit-identical across restarts (np.array_equal, max_abs_diff = 0.0, SHA-256 5ad419a6e0400babbcfc9dbaeb2a6637c3db9c8b38ec644f6050ae5d8a065411); --no-cudnn-deterministic verified live and in saved config.yaml ({deterministic: false, benchmark: true}).

…tarts

With identical observation, prompt, and fixed seed, Action policy server
inference varied across OS process restarts because Wan2.2 VAE observation
encoding (`WanVAE_` in `bfloat16`) ran under `cudnn.benchmark=True` and
`cudnn.deterministic=False`, selecting nearly-tied convolution kernels with
different bf16 reduction orders on first use per process.

- Add tri-state `cudnn_deterministic: bool | None = None` to `SetupOverrides`
  / `SetupArgs` so non-policy inference preserves existing cuDNN autotuning by
  default (`None`), while explicit `True` / `False` configures both HF /
  frozen-config checkpoints (`Cosmos3OmniModel.from_pretrained_dcp`) and
  module-config DCP checkpoints (`OmniInference._create` -> `trainer.cudnn`).
- Normalize bracketed `experiment_overrides` in `ConfigOverrides._build_config`,
  `CheckpointOverrides._build_checkpoint`, `OmniInference._create`, and the
  LIBERO/RoboCasa introspection fallback so module-config DCP setups accept the
  same bracketed CLI syntax as sample overrides.
- Default `action_policy_server_robolab`, `action_policy_server_libero`, and
  `action_policy_server_robocasa` to `--cudnn-deterministic` (with
  `--no-cudnn-deterministic` opt-out), report the live post-load cuDNN flags in
  server logs/metadata, and document reproducibility flags in
  `docs/action_policy_droid_server.md`.
- Add L0 CPU unit/Hydra tests and a 1-GPU cross-process `WanVAE_` determinism
  regression test.

Fixes #448

Signed-off-by: Kane <153349620+kane-vln@users.noreply.github.com>
@kane-vln
kane-vln force-pushed the kane-vln/bug-policy-inference-isnt-reproducible-across-re branch from 6d9ce38 to 3fd5e4a Compare December 4, 2026 12:18
…cuDNN test

Clarify in docs/action_policy_droid_server.md that because the policy
server compiles with torch.compile by default, cross-restart action
equality under --deterministic-seed also requires keeping a persistent
TorchInductor cache (TORCHINDUCTOR_CACHE_DIR), whereas clearing or
rebuilding the cache triggers fresh compiler autotuning.

In test_policy_servers_report_effective_post_load_cudnn_flags, stub
_get_device_memory_bytes alongside the mocked torch.cuda.is_available
check so the L0 CPU test runs cleanly on GPU-less hosts without NVML or
an NVIDIA driver, and replace function-scoped monkeypatch assignments on
torch.backends.cudnn with direct assignments inside try/finally so
fixture teardown cannot overwrite the restored process-wide cuDNN flags.

Signed-off-by: Kane <153349620+kane-vln@users.noreply.github.com>
@kane-vln
kane-vln marked this pull request as ready for review December 4, 2026 13:07

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Policy inference isn't reproducible across restarts: cudnn.benchmark picks the VAE conv algorithm per process

1 participant