Repository navigation
fix: build, test and lower on PyTorch nightly, and let Debugger work again - #5059
Open
shoumikhin wants to merge 6 commits into
Open
shoumikhin wants to merge 6 commits into
shoumikhin wants to merge 6 commits into
Conversation
This was referenced Nov 16, 2026
shoumikhin
force-pushed
the
fix-torch-jit-removal
branch
from
November 18, 2026 19:18
e996215 to
23bacb3
Compare
shoumikhin
force-pushed
the
fix-torch-jit-removal
branch
from
November 18, 2026 23:43
23bacb3 to
13b8b18
Compare
shoumikhin
force-pushed
the
fix-torch-jit-removal
branch
from
November 19, 2026 15:42
13b8b18 to
1ee43a9
Compare
This was referenced Nov 19, 2026
Contributor
Author
|
@zewenli98 this one unblocks CI for the other open PRs. It fixes Torch-TensorRT on the PyTorch nightly, which removed TorchScript from Python and turned processed_hashes into a dict. The one red job failed while downloading the TensorRT wheel, so it only needs a rerun. Could you take a look? |
shoumikhin
force-pushed
the
fix-torch-jit-removal
branch
from
November 20, 2026 02:38
1ee43a9 to
f4b49c1
Compare
shoumikhin
force-pushed
the
fix-torch-jit-removal
branch
from
November 21, 2026 09:03
f4b49c1 to
eccf3a9
Compare
This was referenced Nov 21, 2026
Before it exports a model, Torch-TensorRT asks whether ModelOpt quantized it. That check imported ModelOpt's quantization package whenever ModelOpt was installed. On PyTorch builds that ModelOpt does not support, such as the PyTorch 2.16 nightly where torch.jit.script is gone, that import raises, so every compile failed, even for a model that was never quantized. ModelOpt's own is_quantized only looks for instances of its TensorQuantizer class, from modelopt.torch.quantization.nn, and a model can only hold one once that class is loaded. So look the class up in sys.modules and never import anything. Where ModelOpt works, the answer is the same as before. An import that is blocked (a None entry in sys.modules) or still running in another thread also gives an answer instead of an error. MutableTorchTensorRTModule had its own copy of the check, which caught only ImportError and so failed the same way. It now uses the shared one. Tests cover a ModelOpt whose import failed partway (it must not be imported again), a ModelOpt whose quantization package is blocked in sys.modules, a ModelOpt nn module that is still importing and has no TensorQuantizer yet (both give an answer, not an error), and a model that holds a loaded TensorQuantizer (True). Signed-off-by: Anthony Shoumikhin <[email protected]>
The PyTorch 2.16 nightly removed torch.jit.script, trace, save and load. Skip the tests that need them, with a reason that says so, instead of failing: - tests/py/ts: a new conftest marks the folder's tests as skipped, with the same pytest_collection_modifyitems hook as the conversion and runtime test folders. The classes that do not need TorchScript (TestInput and TestLoggingAPIs, 9 tests) carry a new runs_without_torchscript marker and keep running. The marker sits on the classes, so renaming one does not silently skip it. - test_004_runtime_settings.py: the 4 tests that build a module with torch.jit.trace. - test_export_serde.py: test_save_load_ts, which saves in the TorchScript format. - test_load_compatibility.py: the jit round trip. The other tests keep running. They stub torch.jit.load, adding it where the build has none, so the case that falls back to torch.jit.load still runs. - The tests that import NVIDIA Model Optimizer (ModelOpt), or need the tensorrt.quantize_op converter that Torch-TensorRT registers only after ModelOpt imports. ModelOpt decorates a function with @torch.jit.script when it is imported, so no ModelOpt release imports on this nightly. Their skip conditions now also check for torch.jit.script, in the lowering, ExecuTorch, models and LLM tests. test_fp8_mha_fused_kernel needs that converter but had no ModelOpt check, so it gets the same one. test_fp8_mha_softmax_quantizer_annotation keeps running: it only needs the operator, which ModelOpt registers before the failing line. Signed-off-by: Anthony Shoumikhin <[email protected]>
PyTorch main changed FakeTensorUpdater.processed_hashes from a set of node hashes to a dict keyed by node (pytorch/pytorch#204337). Our FakeTensorUpdater subclass still calls processed_hashes.discard(), so on PyTorch main and nightly it fails with AttributeError: 'dict' object has no attribute 'discard' whenever the graph has a call_function node without meta["val"]. This breaks post_lowering for such graphs, for example the write-back copy_ left by functionalizing an in-place custom op. Pop the node from the dict when processed_hashes is a dict, and keep the old set path for PyTorch builds made before that change, which the current torch>=2.16.0.dev pin still allows. Add a small test that removes meta["val"] from a node of an exported graph and checks that FakeTensorUpdater fills it in again. Signed-off-by: Anthony Shoumikhin <[email protected]>
Debugger passes its settings to compile_module by writing the
_debugger_config entry of the function's keyword defaults
(f.__kwdefaults__). fn_supports_debugger records which function that is.
placed under @fn_supports_debugger. With that order, fn_supports_debugger
records the lock's wrapper instead of compile_module. The wrapper only
takes *args and **kwargs, so its __kwdefaults__ is None, and entering
any Debugger fails with:
TypeError: 'NoneType' object does not support item assignment
Put @fn_supports_debugger innermost, so it records compile_module itself.
The lock still wraps every call, and the wrapper passes the call through
to compile_module, which reads its own keyword defaults.
Add a test that enters a Debugger and checks that compile_module's
_debugger_config default is the Debugger's config, and None afterwards.
Signed-off-by: Anthony Shoumikhin <[email protected]>
…GroupNCCL PyTorch nightly builds no longer ship the legacy c10d ProcessGroupNCCL header. Only the newer nccl2 process group is left. The runtime included the legacy header whenever NCCL collectives were enabled, so the build failed against these nightlies. Include the legacy header, and look for the legacy class, only when the header exists. The nccl2 path already covers the new builds. On PyTorch versions that still have the legacy class, nothing changes. Signed-off-by: Anthony Shoumikhin <[email protected]>
On Linux, torch_tensorrt.dynamo._defaults looks up the current user name
at import time with pwd.getpwuid(os.getuid()). The name only goes into
the default debug log folder and runtime cache path under the temp
directory.
pwd.getpwuid raises KeyError when the uid is not in the passwd
database. This is common in containers started with an arbitrary uid,
for example "docker run --user 12345". There, "import torch_tensorrt"
fails before any user code runs:
KeyError: 'getpwuid(): uid not found: 12345'
Fall back to the numeric uid when the name is unknown, so the folder
becomes torch_tensorrt_12345 instead.
getpass.getuser() names the folder for downloaded TensorRT-LLM plugins
and offloaded engines. Import reaches it when USE_TRTLLM_PLUGINS is set.
It ends in the same lookup when the user name environment variables are
unset, and raises KeyError, or OSError on Python 3.13 and newer. Give it
the same fallback.
Signed-off-by: Anthony Shoumikhin <[email protected]>
shoumikhin
force-pushed
the
fix-torch-jit-removal
branch
from
November 25, 2026 11:37
3b3ebfa to
5e87977
Compare
This branch has not been deployed
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.
What is wrong today
The PyTorch 2.16 nightly breaks Torch-TensorRT, and
Debuggerfails onmain.TorchScript is gone from Python.
torch.jit.script,trace,saveandloadno longer exist. Before export, Torch-TensorRT imports NVIDIA ModelOpt to check for quantization, and ModelOpt callstorch.jit.scripton import. So every compile fails:Tests that need TorchScript or ModelOpt fail instead of skipping.
processed_hashesis now a dict (pytorch/pytorch#204337).FakeTensorUpdatercalls.discard(...)on it, so some graphs fail with'dict' object has no attribute 'discard'.The C++ runtime does not build. The nightly removed the legacy
ProcessGroupNCCLheader (pytorch/pytorch#205374), which the NCCL runtime includes.Entering a
Debuggerfails onmain.compile_modulegot a lock wrapper above@fn_supports_debugger, so the Debugger writes its config into the wrapper's keyword defaults, which areNone:What this change does
is_quantized_by_modeloptno longer imports ModelOpt. It looks for instances of ModelOpt'sTensorQuantizerclass fromsys.modules, like ModelOpt's own check. Where ModelOpt works, the answer is the same.tests/py/ts(classes markedruns_without_torchscriptstill run), the TorchScript cases in the runtime settings, serde and load tests, and tests that need ModelOpt or itsquantize_opconverter.FakeTensorUpdaterhandles both the dict and the older set.ProcessGroupNCCLheader only if it exists; nccl2 covers newer nightlies.@fn_supports_debuggermoves under the lock decorator, so it recordscompile_moduleitself.import torch_tensorrtworks for a user id with no name, likedocker run --user 12345. Its temp folder names use the number.What was tested
Linux x86_64, A100:
MutableTorchTensorRTModule. Onmainboth fail.is_quantizedon an INT8 and a plain model, and the ModelOpt graph tests inloweringandmodelspass.shared_bool_masklowering tests andtest_lazy_engine_init_with_layer_infopass. Thelowering,runtime,executorchandconversionfolders have no new failures versusmain.