Skip to content

fix(vllm_engine): actually export VLLM_BATCH_INVARIANT=1 for deterministic inference - #202

Merged
CalvinXKY merged 3 commits into
mainfrom
fix/deterministic-inference-batch-invariant
Jun 9, 2026
Merged

fix(vllm_engine): actually export VLLM_BATCH_INVARIANT=1 for deterministic inference#202
CalvinXKY merged 3 commits into
mainfrom
fix/deterministic-inference-batch-invariant

Conversation

@aoshen02

@aoshen02 aoshen02 commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Problem

--vllm-enable-deterministic-inference's help text promises it:

Forwards a per-sample seedAND exports VLLM_BATCH_INVARIANT=1 to the vLLM subprocess so attention / comm / MM kernels pick batch-invariant variants. Both are required for true determinism — seed alone does not control kernel selection.

But no code ever set VLLM_BATCH_INVARIANT. Grepping the tree, the only occurrence was that help string:

  • the flag's only runtime effect is the per-sample seed (vime/rollout/vllm_rollout.py);
  • it's an orchestration-only dest (_VIME_ORCHESTRATION_DESTS), so it is not forwarded to vllm serve;
  • build_vllm_subprocess_env never set it.

The only thing that ever exported the env was a line in scripts/run-qwen2.5-0.5B-reproducibility.sh's runtime-env-json (added in #39), which #180 dropped when it re-created that script — leaving nothing to set it. So --vllm-enable-deterministic-inference did not actually give batch-invariant kernels, and the reproducibility recipe lost bitwise determinism silently.

Fix

Set VLLM_BATCH_INVARIANT=1 in build_vllm_subprocess_env when the flag is on, so the flag delivers its documented behavior regardless of launch script. Seed + kernel selection now both hold.

if getattr(args, "vllm_enable_deterministic_inference", False):
    env["VLLM_BATCH_INVARIANT"] = "1"

Tests

Two unit tests in tests/unit/backends/vllm_utils/test_vllm_engine.py:

  • flag on → VLLM_BATCH_INVARIANT == "1"
  • flag off → not set

Both pass (pytest -k "batch_invariant or subprocess_env" → 3 passed).

🤖 Generated with Claude Code

…istic inference

--vllm-enable-deterministic-inference's help text promises it "exports
VLLM_BATCH_INVARIANT=1 to the vLLM subprocess so attention / comm / MM kernels
pick batch-invariant variants", but no code did so -- the flag only forwarded a
per-sample seed, and (being an orchestration-only dest) is never passed to
`vllm serve`. The only thing that ever set the env was a line in
run-qwen2.5-0.5B-reproducibility.sh's runtime-env, which #180 dropped when it
re-created the script, leaving nothing to set it.

Set VLLM_BATCH_INVARIANT=1 in build_vllm_subprocess_env when the flag is on, so
the flag delivers on its documented behavior and seed+kernel determinism both
hold without depending on the launch script. Adds two unit tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds logic to set the VLLM_BATCH_INVARIANT environment variable to '1' in the vLLM subprocess environment when vllm_enable_deterministic_inference is enabled. It also adds unit tests to verify this behavior. There are no review comments, so I have no feedback to provide.

aoshen02 and others added 2 commits June 9, 2026 03:33
slime sets SLIME_ENABLE_PROFILING here and reads it via its sglang *source
patch* (docker/patch/*/sglang.patch: envs.SLIME_ENABLE_PROFILING.get()), which
gates prefill/decode timing instrumentation in sglang's scheduler. vime runs
vLLM and does not patch that instrumentation in, and nothing in the tree reads
VIME_ENABLE_PROFILING -- it was a mechanical slime->vime rename of a flag whose
backing reader never came along, so setting it did nothing. Remove it (and the
now-unused `import os`); vime profiling is driven by --vllm-profiler-config.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: aoshen02 <aoshen@inferact.ai>
@CalvinXKY
CalvinXKY merged commit bfe042d into main Jun 9, 2026
11 of 14 checks passed
momo609 pushed a commit that referenced this pull request Jun 10, 2026
…istic inference (#202)

* fix(vllm_engine): actually export VLLM_BATCH_INVARIANT=1 for deterministic inference

--vllm-enable-deterministic-inference's help text promises it "exports
VLLM_BATCH_INVARIANT=1 to the vLLM subprocess so attention / comm / MM kernels
pick batch-invariant variants", but no code did so -- the flag only forwarded a
per-sample seed, and (being an orchestration-only dest) is never passed to
`vllm serve`. The only thing that ever set the env was a line in
run-qwen2.5-0.5B-reproducibility.sh's runtime-env, which #180 dropped when it
re-created the script, leaving nothing to set it.

Set VLLM_BATCH_INVARIANT=1 in build_vllm_subprocess_env when the flag is on, so
the flag delivers on its documented behavior and seed+kernel determinism both
hold without depending on the launch script. Adds two unit tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* rollout: drop dead VIME_ENABLE_PROFILING env (no reader in vime)

slime sets SLIME_ENABLE_PROFILING here and reads it via its sglang *source
patch* (docker/patch/*/sglang.patch: envs.SLIME_ENABLE_PROFILING.get()), which
gates prefill/decode timing instrumentation in sglang's scheduler. vime runs
vLLM and does not patch that instrumentation in, and nothing in the tree reads
VIME_ENABLE_PROFILING -- it was a mechanical slime->vime rename of a flag whose
backing reader never came along, so setting it did nothing. Remove it (and the
now-unused `import os`); vime profiling is driven by --vllm-profiler-config.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* Update vllm_engine.py

Signed-off-by: aoshen02 <aoshen@inferact.ai>

---------

Signed-off-by: aoshen02 <aoshen@inferact.ai>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@CalvinXKY
CalvinXKY deleted the fix/deterministic-inference-batch-invariant branch June 16, 2026 11:34
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.

2 participants