Replace unimplemented with unimplemented_v2 for dynamo (#148158)

torch/_dynamo/variables/constant.py

https://github.com/pytorch/pytorch/issues/147913

Pull Request resolved: https://github.com/pytorch/pytorch/pull/148158
Approved by: https://github.com/williamwen42, https://github.com/Skylion007
This commit is contained in:
FFFrog 2025-03-01 17:11:58 +08:00 committed by PyTorch MergeBot
parent b162b1600b
commit 1bbe57336b

View File

@ -14,8 +14,8 @@ from typing import TYPE_CHECKING
import torch
from torch._dynamo.source import AttrSource, GetItemSource
from .. import variables
from ..exc import raise_observed_exception, unimplemented
from .. import graph_break_hints, variables
from ..exc import raise_observed_exception, unimplemented_v2
from ..utils import cmp_name_to_op_mapping, common_constant_types, istype, np
from .base import VariableTracker
@ -232,7 +232,14 @@ class EnumVariable(VariableTracker):
for member in list(cls_type):
if member.value == value_vt.as_python_constant():
return cls(member, **options)
unimplemented("Enum variable is constructed with non constant values")
unimplemented_v2(
gb_type="Failed to construct Enum variable",
context=f"value: {value_vt}, allowed enum values: {list(cls_type)}",
explanation="Attempted to construct an Enum value that is non-constant (e.g. int, string) "
"or is not an acceptable value for the Enum. "
f"Acceptable values for Enum `{cls_type}`: {list(cls_type)}.",
hints=[*graph_break_hints.USER_ERROR, *graph_break_hints.SUPPORTABLE],
)
def as_proxy(self):
if isinstance(self.value, int):