From 3b90770b896bf87a48cc28cf98068d160f4836cb Mon Sep 17 00:00:00 2001 From: xmarre Date: Wed, 8 Apr 2026 06:54:21 +0200 Subject: [PATCH 1/2] fix torch.compile kwargs --- .gitignore | 1 + torch_compile_lora_safe.py | 32 ++++++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 2185a26..399d31b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # JetBrains IDE settings .idea/ +.codex # Virtual environment .venv/ diff --git a/torch_compile_lora_safe.py b/torch_compile_lora_safe.py index 77a3894..2411d15 100644 --- a/torch_compile_lora_safe.py +++ b/torch_compile_lora_safe.py @@ -328,20 +328,36 @@ class TorchCompileModel_LoRASafe: @staticmethod def _build_compile_kwargs(backend, mode, fullgraph, dynamic, disable_cudagraphs): - compile_kw = dict( - backend=backend, - fullgraph=fullgraph, - dynamic=dynamic, - ) - if mode != "default": - compile_kw["mode"] = mode + compile_kw = { + "backend": backend, + "fullgraph": fullgraph, + "dynamic": dynamic, + } options = {} if _skip_torch_compile_dict is not None: options["guard_filter_fn"] = _skip_torch_compile_dict if disable_cudagraphs and backend == "inductor": options["triton.cudagraphs"] = False - if options: + + # torch.compile rejects calls that specify both `mode` and `options`. + # When we need extra backend options as well as a preset mode, expand + # the mode preset into concrete backend options and merge them. + if mode != "default": + if options: + list_mode_options = getattr(torch._inductor, "list_mode_options", None) + if list_mode_options is None: + raise RuntimeError( + "Selected a non-default torch.compile mode together with backend options, " + "but this PyTorch build does not expose torch._inductor.list_mode_options() " + "to merge them safely." + ) + merged_options = dict(list_mode_options(mode) or {}) + merged_options.update(options) + compile_kw["options"] = merged_options + else: + compile_kw["mode"] = mode + elif options: compile_kw["options"] = options return compile_kw From f6646e6a0d90989859f309770952baa495422e47 Mon Sep 17 00:00:00 2001 From: xmarre Date: Wed, 8 Apr 2026 07:04:16 +0200 Subject: [PATCH 2/2] Remove project metadata and publish workflow --- torch_compile_lora_safe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_compile_lora_safe.py b/torch_compile_lora_safe.py index 2411d15..6ddb8f6 100644 --- a/torch_compile_lora_safe.py +++ b/torch_compile_lora_safe.py @@ -352,7 +352,7 @@ class TorchCompileModel_LoRASafe: "but this PyTorch build does not expose torch._inductor.list_mode_options() " "to merge them safely." ) - merged_options = dict(list_mode_options(mode) or {}) + merged_options = dict(list_mode_options(mode, dynamic) or {}) merged_options.update(options) compile_kw["options"] = merged_options else: