Skip to content

Studio small-host INT8: armed layers compile once (eager-only call counters, follow-up to #17167) - #17193

Merged
danielhanchen merged 2 commits into
mainfrom
dh/small-host-int8-counts-eager-only
Nov 9, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
dh/small-host-int8-counts-eager-only

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Follow-up to #17167. That PR arms the existing small-host INT8 layers (Int8WeightLinear.act_int8 = True) for an explicit Turing INT8 request, so families such as FLUX.1 now run with armed layers too. Every forward of an armed layer increments a module-level diagnostic counter (_INT8_ACT_COUNTS["dequant"] on the weight-only branch, ["int8_act"] on the W8A8 branch). Under torch.compile, Dynamo guards on the exact value of that global int, so each call invalidates the last graph and recompiles:

  • default compile: 8 frames for 12 identical calls, then an eager fallback for that layer
  • fullgraph=True: call 9 raises FailOnRecompileLimitHit
  • with Studio's raised recompile limit (64) this only delays the problem

An fp16 pipeline makes it worse. _int8_act_ok declines fp16 on the dtype check, so the newly armed layer takes the weight-only dequant branch exactly as before, except that it now also bumps the counter.

Fix

The counters are eager-only diagnostics, and nothing in the backend reads them during a render. forward now skips the increment when torch.compiler.is_compiling() is true. Inside a trace that check is a constant, so it adds no graph break. Eager counting is unchanged. The math on both branches is unchanged, and UNSLOTH_DIFFUSION_SMALL_HOST_INT8_ACT=0 still turns W8A8 off.

Test (CPU, torch 2.12.1)

test_diffusion_small_host_int8_act.py::test_armed_layer_compiles_once_and_still_counts_eager_calls builds a real armed Int8WeightLinear in fp16, so it takes the dequant branch. An eager call bumps the counter by one. The test then compiles the layer with fullgraph=True and a frame-counting backend and runs 12 calls.

Tree Result
main FAILED: FailOnRecompileLimitHit: Hard failure due to fullgraph=True
this PR passed: 1 frame for 12 calls, every output bit-equal to eager

All small-host test files (test_diffusion_small_host*.py, test_video_small_host.py): 127 passed, 7 skipped.

Not covered

  • No GPU run. The W8A8 branch (Turing torch._int_mm) takes the same counter change, but it was not compiled on a T4 here.

@danielhanchen danielhanchen self-assigned this Nov 9, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T02:52:56.550781Z 65ff9d1 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 65ff9d157d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 4acaa6c into main Nov 9, 2026
@danielhanchen
danielhanchen deleted the dh/small-host-int8-counts-eager-only branch November 9, 2026 12:42
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.

1 participant