From 0ab095eb3f522bf552423d43a65052122830babe Mon Sep 17 00:00:00 2001 From: Zhaoyi Li <36555117+Lzy17@users.noreply.github.com> Date: Fri, 3 Jul 2026 05:20:36 -0500 Subject: [PATCH] [AMD]: hot-patch transformers dynamic_module_utils symlink bug (#29986) --- docker/rocm.Dockerfile | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docker/rocm.Dockerfile b/docker/rocm.Dockerfile index 79a93f197..4a6d6686f 100644 --- a/docker/rocm.Dockerfile +++ b/docker/rocm.Dockerfile @@ -622,6 +622,36 @@ RUN if [ "$BUILD_TRITON" = "1" ]; then \ && if [ -d python/triton_kernels ]; then pip install -e python/triton_kernels --no-deps; fi; \ fi +# ----------------------- +# Hot patch: transformers dynamic_module_utils symlink bug (v5.12.1). +# _compute_local_source_files_hash calls Path(...).resolve() on custom-code +# module files, following the HF-cache snapshots//x.py -> blobs/ +# symlink. trust_remote_code models whose custom code uses relative imports +# (e.g. Kimi-K2.6's kimi_k25_vision_processing.py: `from .media_utils import`) +# then crash with FileNotFoundError: .../blobs/.py at processor init. +# Mirrors upstream transformers PR #46618 (merged, not yet released): drop the +# .resolve() on the module file and its relative-import sources so the snapshot +# .py names (not the blob targets) are used. Self-skips once transformers ships +# the fix; fails the build loudly if the pattern is present but unpatched. +RUN python3 - <<'PY' +import pathlib +import transformers.dynamic_module_utils as m + +MARKS = ["Path(resolved_module_file).resolve()", "Path(source_file).resolve()"] +path = pathlib.Path(m.__file__) +src = path.read_text() +if not any(mark in src for mark in MARKS): + print("transformers dynamic_module_utils already fixed; no patch needed") +else: + patched = ( + src.replace("Path(resolved_module_file).resolve()", "Path(resolved_module_file)") + .replace("Path(source_file).resolve()", "Path(source_file)") + ) + assert patched != src, "FATAL: transformers symlink patch matched nothing" + path.write_text(patched) + print("patched transformers dynamic_module_utils.py (symlink hash fix)") +PY + # ----------------------- # Performance environment variable.