shallow_copy_and_detach_core Class — pytorch Architecture
Architecture documentation for the shallow_copy_and_detach_core class in SparseCsrTensorImpl.h from the pytorch codebase.
Entity Profile
Source Code
aten/src/ATen/SparseCsrTensorImpl.h lines 112–143
template <typename VariableVersion>
c10::intrusive_ptr<TensorImpl> shallow_copy_and_detach_core(
VariableVersion&& version_counter,
bool allow_tensor_metadata_change) const {
const auto mode_stack_len = c10::impl::TorchDispatchModeTLS::stack_len();
c10::impl::PyInterpreter&& interpreter = nullptr;
if (mode_stack_len > 0 &&
!c10::impl::tls_is_dispatch_key_excluded(DispatchKey::Python)) {
const auto& cur_torch_dispatch_mode_state =
c10::impl::TorchDispatchModeTLS::get_stack_at(mode_stack_len - 1);
interpreter = cur_torch_dispatch_mode_state->pyinterpreter();
} else if (
key_set_.has(DispatchKey::Python) &&
!c10::impl::tls_is_dispatch_key_excluded(DispatchKey::Python)) {
interpreter = pyobj_slot_.load_pyobj_interpreter();
} else {
// otherwise just copy the SparseTensorImpl and not the PyObject.
auto impl = c10::make_intrusive<SparseCsrTensorImpl>(
key_set(), device(), layout_impl(), dtype());
copy_tensor_metadata(
/*src_sparse_impl=*/this,
/*dest_sparse_impl=*/impl.get(),
/*version_counter=*/version_counter,
/*allow_tensor_metadata_change=*/allow_tensor_metadata_change);
impl->refresh_numel();
return impl;
}
auto r = interpreter->detach(this);
r->set_version_counter(std::forward<VariableVersion>(version_counter));
r->set_allow_tensor_metadata_change(allow_tensor_metadata_change);
return r;
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free