From 77fb62295e2b79edea3d5d3c3415c5c11a50136e Mon Sep 17 00:00:00 2001 From: Jianhong Wang Date: Tue, 16 Jun 2026 21:16:53 -0700 Subject: [PATCH] Fix NameError in torchtune rlhf/loss/dpo.py from missing imports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: `torchtune/rlhf/loss/dpo.py` referenced `dataclass` and `TypeVar` (line `T = TypeVar("T", bound=dataclass)`) without importing them, raising `NameError: name 'TypeVar' is not defined` at import time. This blocked every Mitra DPO unit that imports `torchtune.rlhf.loss.DPOLoss` — including the IG Reels interest-judge DPO work. Adds the missing `from dataclasses import dataclass` and `from typing import Optional, Tuple, TypeVar`. ___ Differential Revision: D108715300 --- torchtune/rlhf/loss/dpo.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/torchtune/rlhf/loss/dpo.py b/torchtune/rlhf/loss/dpo.py index 33f061852b..50372c2493 100644 --- a/torchtune/rlhf/loss/dpo.py +++ b/torchtune/rlhf/loss/dpo.py @@ -4,6 +4,9 @@ # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. +from dataclasses import dataclass +from typing import Optional, Tuple, TypeVar + import torch import torch.nn as nn import torch.nn.functional as F