(
self,
tx,
name,
args: "List[VariableTracker]",
kwargs: "Dict[str, VariableTracker]",
constant=False,
)
| 332 | ) |
| 333 | |
| 334 | def call_method( |
| 335 | self, |
| 336 | tx, |
| 337 | name, |
| 338 | args: "List[VariableTracker]", |
| 339 | kwargs: "Dict[str, VariableTracker]", |
| 340 | constant=False, |
| 341 | ) -> "VariableTracker": |
| 342 | from . import ConstantVariable, ListIteratorVariable, TupleVariable |
| 343 | |
| 344 | key = self.module_key |
| 345 | module = tx.output.get_submodule(key) |
| 346 | |
| 347 | def generic_call_method_helper(name): |
| 348 | # Helper function to put a `call_method` node in FX graph, |
| 349 | # with nn.Module as the first arg. |
| 350 | mod_proxy = tx.output.create_proxy( |
| 351 | "get_attr", |
| 352 | self.module_key, |
| 353 | tuple(), |
| 354 | {}, |
| 355 | ) |
| 356 | mod_proxy.node.meta["example_value"] = module |
| 357 | |
| 358 | proxy_args, proxy_kwargs = proxy_args_kwargs(args, kwargs) |
| 359 | |
| 360 | from .builder import wrap_fx_proxy |
| 361 | |
| 362 | return wrap_fx_proxy( |
| 363 | tx=tx, |
| 364 | proxy=tx.output.create_proxy( |
| 365 | "call_method", |
| 366 | name, |
| 367 | args=(mod_proxy, *proxy_args), |
| 368 | kwargs=proxy_kwargs, |
| 369 | ), |
| 370 | ) |
| 371 | |
| 372 | if name in ["_call_impl", "_wrapped_call_impl"]: |
| 373 | # Example: `self.layer.__call__(x)` |
| 374 | # This is used for explicit calling `__call__` in a forward function. |
| 375 | # Dynamo inlines `__call__`, includes hooks. |
| 376 | return self.call_function(tx, args, kwargs) |
| 377 | elif name == "forward": |
| 378 | # Example: `self.layer.forward(x)` |
| 379 | # This is used for explicit calling `forward` in a forward function. |
| 380 | # Dynamo puts `call_method` node in FX, doesn't trigger hooks. |
| 381 | with record_nn_module_stack(self.module_key, self.source, tx, module): |
| 382 | return generic_call_method_helper(name) |
| 383 | |
| 384 | if name == "_check_input_dim" and skipfiles.is_torch_inline_allowed( |
| 385 | inspect.getfile(module.__class__._check_input_dim) |
| 386 | ): |
| 387 | return ConstantVariable.create(True) |
| 388 | |
| 389 | if name == "_get_item_by_idx": |
| 390 | assert args[1].is_python_constant() |
| 391 | assert isinstance(args[0], TupleVariable) |
no test coverage detected