Repository navigation
Conversation
torch.fx keeps its "symbolic tracing in progress" flag in a process-wide global. Under --data_parallel the thread ranks (and the sharded collection threads) run compiled quant functions concurrently; when one of them (re)compiles a specialization it meets first (a new shape, device or grad mode -- e.g. the no-grad final qdq at the block tail, or a warm block whose first phase runs concurrent), every peer entering a compiled function sees the flag and dynamo raises "Detected that you are using FX to symbolically trace a dynamo-optimized function". Observed on Qwen3.8-27B, iters 10, --data_parallel 4, block 1 (nondeterministic). Each engine thread now runs with dynamo's error_on_nested_fx_trace off, so such a peer call runs eagerly instead (same result, no compile for that one call); the tracing thread is unaffected (its dispatch modes are thread-local). The setting is scoped per thread: dynamo's config lives in context variables. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: avtc <tarasenkov@gmail.com>
Follow-up to intel#2351. Under --data_parallel the AWQ transform ran entirely on the home device while the other devices idled: its calibration forward, the smoothing-ratio grid search and the clip search. All three now shard over the collection devices; the quantized model is bit-identical to the serial run. - Calibration capture (Step 1): the pass carrying the preprocessors' hooks shards over one-pass copies of the block (the mirror pool is built after the transform, whose weights it must carry) when every preprocessor in it opts in via the new BasePreprocessor.sharded_calibration(devices). AWQ routes each replica's captures into its device's buffer, keeps the captured parent calls on that device (copied, never aliasing a live activation) and merges in device order -- the sample order of the contiguous shards -- re-accumulating the per-call activation sums so every statistic equals the serial one. Passes the engine would not shard keep the serial, host-parked capture. - Grid search: the cached parent calls split into contiguous slices; each device replays its slice on a private copy of the mapping's parent (the home slot on the parent itself) and returns the per-candidate loss sums plus its element count; the serial selection runs on sum / count. - Clip search: the independent per-layer searches map over the devices on copies of the layer weights. The engine side is a block-scoped search seam (auto_round/algorithms/parallel/search_shard.py) that the composer attaches around pre_quantize_block only; replica copies are built straight on their device and all exist before any evaluation starts. Searches that cannot shard (too few calls, a parent outside the block, a balance layer outside the parent, an empty replay) keep the serial loop, which is unchanged. AR_PERF_COUNTERS adds per-block "[perf] pipeline phases" and "[perf] awq searches" lines and a "[perf] awq grid split" line per grid search. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: avtc <tarasenkov@gmail.com>
|
Azure Pipelines: Successfully started running 5 pipeline(s). 3 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
This comment has been minimized.
This comment has been minimized.
…rocess-wide torch>=2.14 keeps torch.fx's "tracing in progress" flag per thread (_is_fx_tracing_tls); only torch<2.14 keeps it in the module global _is_fx_tracing_flag that a peer thread's trace leaks through. On per-thread torch there is no cross-thread race, so tolerate_concurrent_traces() is now a no-op there instead of turning error_on_nested_fx_trace off. The tests that simulate a peer's trace by setting the global flag skip on per-thread torch (CI runs torch 2.15, where the attribute no longer exists and the tests failed in setup); new tests pin the no-op guard and that a per-thread flag hides a peer's trace from compiled calls. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: avtc <tarasenkov@gmail.com>
Collaborator
|
/azp run Unit-Test-CUDA-AutoRound |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Follow-up to #2351. Under
--data_parallel, AWQ (--algorithm awq,awq,auto_round) ran entirely on the home GPU while the other GPUs idled: its calibration forward, the smoothing-ratio grid search and the clip search. This PR shards all three across the same GPUs. The quantized model is bit-identical to the serial run. It also fixes atorch.compilecrash in the thread ranks that #2351 left in place.AWQ under
--data_parallelsum / count.auto_round/algorithms/parallel/search_shard.py); the composer attaches it aroundpre_quantize_blockonly. Preprocessors opt in through twoBasePreprocessorhooks:set_parallel_search(seam)for the searches andsharded_calibration(devices)for the calibration pass. The defaults keep everything serial, so other transforms are unaffected.Fix: compiled calls in data-parallel threads
On torch < 2.14,
torch.fxkeeps its "symbolic tracing in progress" flag in a process-wide global (torch 2.14+ keeps it per thread, so the race below cannot happen there). The thread ranks compile some specializations of the quant functions after the serial first phase: a new shape, device or grad mode (for example the no-grad final QDQ at the end of a block). While one rank traces such a compile, a peer that enters a compiled function raisesRuntimeError: Detected that you are using FX to symbolically trace a dynamo-optimized function. Reproduced on Qwen3.8-27B,--iters 10 --data_parallel 4: 3 of 5 runs failed on block 1, with or without AWQ. Each engine thread (spmd.run_ranks,run_threaded_spawn, the search seam) now runs with dynamo'serror_on_nested_fx_traceoff, so such a peer call runs eagerly for that one call. The tracing thread is unaffected (its dispatch modes are thread-local). The setting is applied per thread because dynamo keeps its config in context variables. On torch 2.14+ the guard is a no-op.Measured (Qwen3.8-27B, W4A16 g128,
--algorithm awq, RTN,--iters 0,--device_map 0, 128 samples, RTX 3090; times per block are medians):--data_parallel 4With
--awq_apply_clip, the clip search went from 22.9 to 7.8 s per block before the calibration forward was sharded. On main,--data_parallel 4left the AWQ phases serial: per-block time with clip stayed at the serial level (63-72 s against ~64 s serial).awq,auto_roundwith--iters 10 --data_parallel 4andtorch.compilepasses with the fix (8-block smoke run); before the fix it failed on block 1.Diagnostics. No new options. Under
AR_PERF_COUNTERSthere is a per-block[perf] pipeline phasesline (calibration forward, pre-quantize transforms, reference and quantized-input collection, tuning, cascade), a per-block[perf] awq searchesline, and a[perf] awq grid splitline per grid search (documented indocs/environments.md).docs/step_by_step.mddescribes the sharded AWQ phases.Tests.
test/unit/test_cpu/quantization/test_awq_sharded_search.py(new):duo_scalingmode and the micro-batched replay);test/unit/test_cpu/quantization/test_spmd_ranks.py: compiled calls stay legal in rank and spawned threads while a peer traces. These tests fail without the fix.Type of Change
New feature / Bug fix / Performance
Related Issues
Relates to #2351 (follow-up)
Checklist Before Submitting
/azp run Unit-Test-CUDA-AutoRound.🤖 Generated with Claude Code