mirror of
https://github.com/pytorch/pytorch.git
synced 2025-11-06 00:54:56 +08:00
[dynamo][cpp-guards] Optimize tensor.grad accessor (#123226)
For LayoutLM model, reduces C++ guard overhead by 1.48x. These are the numbers  Pull Request resolved: https://github.com/pytorch/pytorch/pull/123226 Approved by: https://github.com/jansel
This commit is contained in:
committed by
PyTorch MergeBot
parent
9288b27461
commit
d91db70295
@ -170,6 +170,25 @@ class AttrSource(ChainedSource):
|
||||
return f"{self.base.name()}.{self.member}"
|
||||
|
||||
|
||||
# Represents tensor.grad source. It could be represented by AttrSource as well.
|
||||
# But, we could access grad field on tensor directly in C++ without going
|
||||
# through the Python bytecodes. Therefore, we use a separate source for grad
|
||||
# field.
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class GradSource(ChainedSource):
|
||||
member: str = "grad"
|
||||
|
||||
def reconstruct(self, codegen):
|
||||
self.base.reconstruct(codegen)
|
||||
codegen.extend_output(codegen.create_load_attrs(self.member))
|
||||
|
||||
def guard_source(self):
|
||||
return self.base.guard_source()
|
||||
|
||||
def name(self):
|
||||
return f"{self.base.name()}.{self.member}"
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class ParamBufferSource(AttrSource):
|
||||
def guard_source(self):
|
||||
|
||||
Reference in New Issue
Block a user