Skip to content

Commit

Permalink
LazyVT utils to get original value/source and is_hashable (#144160)
Browse files Browse the repository at this point in the history
Summary:
X-link: pytorch/pytorch#144160
Approved by: https://github.com/williamwen42, https://github.com/jansel
ghstack dependencies: #144129, #144130, #144141, #144158, #144163

Reviewed By: jeanschmidt

Differential Revision: D67828360

Pulled By: anijain2305

fbshipit-source-id: 60a4daa9e4bd04b9be7a4c3dd4551ea5e13aac86
  • Loading branch information
anijain2305 authored and facebook-github-bot committed Jan 5, 2025
1 parent 916f107 commit 9028c93
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions userbenchmark/dynamo/dynamobench/_dynamo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2063,12 +2063,27 @@ def is_int_specialization_case(value, source):


def specialize_symnode(arg):
from .variables import ConstantVariable, SymNodeVariable
from .variables import ConstantVariable, LazyVariableTracker, SymNodeVariable

# Guard and specialize
if isinstance(arg, LazyVariableTracker) and not arg.is_realized():
# Find if the arg would be realized as SymNodeVariable later on. If yes,
# realize it and specialize. Else return the arg.

source = arg.original_source()
value = arg.original_value()

is_symnode_vt = is_torch_sym(value) or (
not config.specialize_int
and type(value) is int
and not is_int_specialization_case(value, source)
)

if not is_symnode_vt:
return arg

if isinstance(arg, SymNodeVariable):
return ConstantVariable.create(arg.evaluate_expr())

return arg


Expand Down

0 comments on commit 9028c93

Please sign in to comment.