已合并
[sync] PR-37970: update VariableType to support DEBUG compile #38850
ascend-robot创建于 6月18日
[sync] PR-37970: update VariableType to support DEBUG compile #38850
已合并
共 1 个文件变更+17-5
| @@ -42,13 +42,25 @@ namespace at_npu { namespace autograd { | |||
| 42 | 42 | ||
| 43 | namespace VariableType { | 43 | namespace VariableType { |
| 44 | namespace { | 44 | namespace { |
| 45 | - C10_UNUSED void reset_grad_accumulator(Variable & self) { | 45 | +[[maybe_unused]] void reset_grad_accumulator(Variable& self) { |
| 46 | - AutogradMeta* meta = torch::autograd::impl::get_autograd_meta(self); | 46 | + AutogradMeta* meta = torch::autograd::impl::get_autograd_meta(self); |
| 47 | - if (meta != nullptr) { | 47 | + if (meta != nullptr) { |
| 48 | - meta->grad_accumulator_.reset(); | 48 | + meta->grad_accumulator_.reset(); |
| 49 | - } | ||
| 50 | } | 49 | } |
| 51 | } | 50 | } |
| 51 | +[[maybe_unused]] size_t expected_fresh_use_count(const Variable& self) { | ||
| 52 | + if (!self.defined()) { | ||
| 53 | + // An UndefinedTensorImpl always has a use count of 0 | ||
| 54 | + return 0; | ||
| 55 | + } | ||
| 56 | + if (self.unsafeGetTensorImpl()->pyobj_slot()->load_pyobj() != nullptr) { | ||
| 57 | + // A TensorImpl with a Python object has a use count of 2 | ||
| 58 | + return 2; | ||
| 59 | + } | ||
| 60 | + // A fresh TensorImpl (with no PyObject) has a use count of 1 | ||
| 61 | + return 1; | ||
| 62 | +} | ||
| 63 | +} | ||
| 52 | 64 | ||
| 53 | ${type_derived_method_definitions} | 65 | ${type_derived_method_definitions} |
| 54 | 66 | ||