fix: patch torch._pytree.register_constant + tighten torchao/transformers pins
Browse files- Add no-op shim for torch.utils._pytree.register_constant in train.py
before any torchao/unsloth/transformers import. Fixes AttributeError
when torchao>=0.9 is installed with PyTorch 2.6.0.
- Dockerfile: move torchao==0.6.1 force-reinstall to LAST pip step so
nothing can override it after the fact.
- Dockerfile: tighten transformers pin to <4.48 (4.48+ unconditionally
imports quantizer_torchao at module init, breaking torchao 0.6.1).
- Dockerfile: remove --upgrade from 'pip install -r requirements.txt'
to prevent silent package version bumps.
- Dockerfile +13 -9
- trainer/train.py +10 -0
Dockerfile
CHANGED
|
@@ -12,19 +12,23 @@ WORKDIR /app
|
|
| 12 |
# Upgrade pip
|
| 13 |
RUN pip install --no-cache-dir --upgrade pip
|
| 14 |
|
| 15 |
-
# Install unsloth from GitHub (
|
| 16 |
RUN pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
#
|
| 20 |
-
#
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
# Pin trl and transformers to stable versions
|
| 24 |
-
RUN pip install --no-cache-dir "trl>=0.15,<0.17" "transformers>=4.47,<4.51"
|
| 25 |
|
| 26 |
COPY --chown=user ./requirements.txt requirements.txt
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# Copy all the code
|
| 30 |
COPY --chown=user . /app
|
|
|
|
| 12 |
# Upgrade pip
|
| 13 |
RUN pip install --no-cache-dir --upgrade pip
|
| 14 |
|
| 15 |
+
# Install unsloth from GitHub (drags in bleeding-edge torchao)
|
| 16 |
RUN pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
| 17 |
|
| 18 |
+
# Pin trl and transformers BEFORE locking torchao.
|
| 19 |
+
# transformers>=4.48 unconditionally does `from .quantizer_torchao import ...`
|
| 20 |
+
# at module init, which breaks if torchao is the wrong version.
|
| 21 |
+
# Stay on <4.48 where that import is guarded.
|
| 22 |
+
RUN pip install --no-cache-dir "trl>=0.15,<0.17" "transformers>=4.47,<4.48"
|
|
|
|
|
|
|
| 23 |
|
| 24 |
COPY --chown=user ./requirements.txt requirements.txt
|
| 25 |
+
# No --upgrade here; we don't want pip silently re-upgrading pinned packages.
|
| 26 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 27 |
+
|
| 28 |
+
# CRITICAL: Force-downgrade torchao LAST (after every other install).
|
| 29 |
+
# torchao>=0.7 requires torch.utils._pytree.register_constant which does not
|
| 30 |
+
# exist in PyTorch 2.6.0. This must be the final pip step. (v2)
|
| 31 |
+
RUN pip install --no-cache-dir --force-reinstall "torchao==0.6.1"
|
| 32 |
|
| 33 |
# Copy all the code
|
| 34 |
COPY --chown=user . /app
|
trainer/train.py
CHANGED
|
@@ -1,6 +1,16 @@
|
|
| 1 |
import sys
|
| 2 |
import os
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
os.environ["WANDB_API_KEY"] = "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"
|
| 5 |
os.environ["WANDB_PROJECT"] = "codeforge-grpo"
|
| 6 |
|
|
|
|
| 1 |
import sys
|
| 2 |
import os
|
| 3 |
|
| 4 |
+
# ββ Compatibility shim ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 5 |
+
# torchao>=0.9 decorates enums with @register_as_pytree_constant which calls
|
| 6 |
+
# torch.utils._pytree.register_constant β a function that only exists in
|
| 7 |
+
# PyTorch 2.7+. We're running on 2.6.0, so patch it in before any import
|
| 8 |
+
# of torchao / transformers / unsloth triggers the missing attribute error.
|
| 9 |
+
import torch.utils._pytree as _pytree
|
| 10 |
+
if not hasattr(_pytree, "register_constant"):
|
| 11 |
+
_pytree.register_constant = lambda cls: cls # no-op shim
|
| 12 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 13 |
+
|
| 14 |
os.environ["WANDB_API_KEY"] = "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"
|
| 15 |
os.environ["WANDB_PROJECT"] = "codeforge-grpo"
|
| 16 |
|