add hex method on SymFloat (#139451)

Pull Request resolved: https://github.com/pytorch/pytorch/pull/139451
Approved by: https://github.com/ezyang
This commit is contained in:
Bob Ren 2024-11-01 14:06:50 -07:00 committed by PyTorch MergeBot
parent 8d1eaa3da6
commit fdd298dcb7
2 changed files with 7 additions and 0 deletions

View file

@ -681,6 +681,10 @@ class SymFloat:
"""Returns the complex conjugate of the float."""
return self
def hex(self) -> str:
"""Returns the hexadecimal representation of the float."""
return self.node.guard_float("", 0).hex()
class SymBool:
"""

View file

@ -2384,6 +2384,9 @@ def handle_traced_output(example_value, tx, proxy, options, subclass_type, targe
):
set_example_value(proxy.node, example_value)
return ConstantVariable.create(example_value, **options)
elif isinstance(example_value, str) and (proxy.node.target in ["hex"]):
set_example_value(proxy.node, example_value)
return ConstantVariable.create(example_value, **options)
else:
unimplemented(
"torch.* op returned non-Tensor "