Repository navigation
Studio: install torchao Windows ROCm stub in the inference worker - #7000
Conversation
There was a problem hiding this comment.
Code Review
This pull request ensures that the torchao Windows-ROCm stub is installed in the inference worker before any transformers imports, preventing crashes on Windows ROCm environments. It also introduces a static AST-based test suite to enforce this ordering across all entrypoints. The reviewer identified a potential UnicodeDecodeError on Windows when reading source files with path.read_text() due to non-ASCII characters (e.g., box-drawing characters in comments), and suggested explicitly specifying encoding="utf-8" in both occurrences of read_text().
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| exists in the file); ordering is asserted only for the inference worker below, the path this fix | ||
| hardened. The other three import transformers at structurally different sites.""" | ||
| for path in _ENTRYPOINTS: | ||
| assert _stub_call_linenos(ast.parse(path.read_text())), ( |
There was a problem hiding this comment.
On Windows platforms, calling path.read_text() without specifying an encoding will use the system's default preferred encoding (such as CP1252), which raises a UnicodeDecodeError when encountering non-ASCII characters (like the box-drawing characters ── in worker.py). Specifying encoding="utf-8" ensures the test runs reliably across all platforms.
| assert _stub_call_linenos(ast.parse(path.read_text())), ( | |
| assert _stub_call_linenos(ast.parse(path.read_text(encoding="utf-8"))), ( |
There was a problem hiding this comment.
Fixed in d90fb4f: read_text(encoding="utf-8").
| import), and -- the reason it sits at the top of the function -- the ``_resolve_base_model`` call, | ||
| which pulls transformers via ``utils.models`` for a local LoRA adapter with no recorded base. | ||
| Scoped to the function (mirrors ``test_ssm_runtime``) so a stub call elsewhere in the module can't | ||
| mask a drop from the function that actually runs the import. The ``_activate_transformers_version`` |
There was a problem hiding this comment.
Similar to the previous check, read_text() should specify encoding="utf-8" to prevent UnicodeDecodeError on Windows when parsing files containing non-ASCII characters.
| mask a drop from the function that actually runs the import. The ``_activate_transformers_version`` | |
| tree = ast.parse((_CORE / "inference" / "worker.py").read_text(encoding="utf-8")) |
There was a problem hiding this comment.
Fixed in d90fb4f: read_text(encoding="utf-8").
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8162842c51
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| # _resolve_base_model -> utils.models. See core/_torchao_stub.py; no-op off Windows ROCm. | ||
| from core._torchao_stub import install_torchao_windows_rocm_stub | ||
|
|
||
| install_torchao_windows_rocm_stub() |
There was a problem hiding this comment.
Stub torchao inside tier-probe subprocesses too
This only seeds the stub in the inference worker process. When activation reaches _probe_tier() (for example for a local config saved by transformers 5.x or a tokenizer class that needs 5.x), utils/transformers_version.py runs _PROBE_CONFIG_SCRIPT in a fresh sys.executable process, and that script imports transformers without installing this stub. On the same Windows ROCm legacy venv with real torchao, those probes still import the real package and fail, so tier selection falls back to default/530 before the main process is protected. Please propagate the stub into the probe subprocess as well.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Checked: the tier-probe subprocess only calls AutoConfig.from_pretrained(), which does not import transformers.quantizers/torchao. Verified against the installed transformers, including with a torchao quantization_config present in config.json: no quantizers or torchao modules land in sys.modules. Quantizer resolution only happens in from_pretrained model loading, which this config-only probe never reaches, so there is nothing to stub here.
| # _resolve_base_model -> utils.models. See core/_torchao_stub.py; no-op off Windows ROCm. | ||
| from core._torchao_stub import install_torchao_windows_rocm_stub | ||
|
|
||
| install_torchao_windows_rocm_stub() |
There was a problem hiding this comment.
Keep the torchao stub after the Triton gate
On Windows ROCm hosts without Triton, this call now runs before the Windows Triton check below even though that section says it must precede any torch import; install_torchao_windows_rocm_stub() imports torch to detect ROCm (core/_torchao_stub.py), so TORCHDYNAMO_DISABLE is set only after torch has already been loaded. That can leave torch.compile/Dynamo enabled in exactly the no-Triton Windows path this gate is meant to disable, unlike the training/export workers which still run the Triton gate before installing the stub.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in d90fb4f: the Triton check now runs before the torchao stub (which imports torch to detect ROCm), matching the training/export workers' ordering.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d90fb4fea5
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| # _resolve_base_model -> utils.models. See core/_torchao_stub.py; no-op off Windows ROCm. | ||
| from core._torchao_stub import install_torchao_windows_rocm_stub | ||
|
|
||
| install_torchao_windows_rocm_stub() |
There was a problem hiding this comment.
Stub torchao in tier probes too
On Windows ROCm legacy venvs, this installs the stub only in the inference worker, but the following _activate_transformers_version() path can call _probe_tier() for weak 5.x signals. Fresh evidence: in the current tree, utils/transformers_version.py still runs _PROBE_CONFIG_SCRIPT in a fresh sys.executable process, and that script imports AutoConfig without importing core._torchao_stub; that child can still import the real torchao and report a parse failure, causing tier selection to fall back to default/530 before the protected worker imports transformers, so affected 5.x-only models can load with the wrong transformers version.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Re-checked against the current head: ran the literal _PROBE_CONFIG_SCRIPT as a real subprocess against a config.json with quantization_config={quant_method: torchao}. It exits 0 with no crash and no torchao import (from transformers import AutoConfig; AutoConfig.from_pretrained(...) never touches transformers.quantizers). Quantizer resolution only happens in from_pretrained model loading, which this config-only probe deliberately never reaches. Same conclusion as the prior round (#7000 (comment)), still not reproducible.
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubCodex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback". |
On a Windows ROCm venv that still carries a real torchao (a legacy or manual install, not a fresh post-#6837 one), loading a safetensors model through the inference worker crashes: it imports transformers before torchao is stubbed, so torchao aborts on import with an AttributeError (the crash in #6833), not just the cosmetic warning. Training, export, and rag already install the stub; the inference worker, the most-used path, did not.
Fix
Install
install_torchao_windows_rocm_stub()inrun_inference_processbefore it touches transformers. It is a no-op off Windows ROCm, so nothing changes on any other setup.It goes at the top of the non-MLX path, not just before
import transformers, because the worker can reach transformers earlier: loading a local LoRA adapter with no recorded base resolves the base through_resolve_base_model->utils.models, which imports transformers. The MLX path returns before this and never needs the stub.Tests
test_torchao_stub_worker_parity.py(CPU-only, no torch/GPU): all four workers install the stub, and in the inference worker it runs before every path that reaches transformers. Passes withtest_ssm_runtime.py(49).No live repro here: that needs a Windows AMD ROCm box with a real torchao and a safetensors load. The guarantee is the no-op-off-ROCm behavior plus matching what the three other workers already do.
Related to #6833. The warning is already suppressed on main (#6506, #6712) and the installer skips torchao on Windows ROCm (#6837); this covers venvs the installer never touched. The training and export workers share the same local-adapter gap; fixing them is a separate change.