MCPcopy Create free account
hub / github.com/pytorch/pytorch / tensor

Method tensor

torch/_dynamo/debug_utils.py:562–593  ·  view source on GitHub ↗
(
        self,
        storage,
        shape,
        stride=None,
        *,
        storage_offset=None,
        dtype=None,
        requires_grad=None,
        is_leaf=None,
        **metadata,
    )

Source from the content-addressed store, hash-verified

560 return rand_strided(shape, stride, dtype_hint, device).untyped_storage()
561
562 def tensor(
563 self,
564 storage,
565 shape,
566 stride=None,
567 *,
568 storage_offset=None,
569 dtype=None,
570 requires_grad=None,
571 is_leaf=None,
572 **metadata,
573 ):
574 stride = _stride_or_default(stride, shape=shape)
575 storage_offset = _storage_offset_or_default(storage_offset)
576 dtype = _dtype_or_default(dtype)
577 is_leaf = _is_leaf_or_default(is_leaf)
578 requires_grad = _requires_grad_or_default(requires_grad)
579 t = torch.tensor(
580 [], dtype=dtype, device=storage.device, requires_grad=requires_grad
581 )
582 with torch.no_grad():
583 t.set_(storage, storage_offset, shape, stride)
584 if not is_leaf:
585 # Fake up some autograd history in a very naughty way
586 with torch.enable_grad():
587 t = t.clone(memory_format=torch.preserve_format)
588 with torch.no_grad():
589 t.set_(storage, storage_offset, shape, stride)
590 assert torch._subclasses.meta_utils.safe_is_leaf(t) == is_leaf
591 torch._utils.set_tensor_metadata(t, metadata)
592 self.args.append(t)
593 return t # for BC
594
595 def symint(self, val):
596 self.args.append(val)

Callers 15

_toMethod · 0.45
is_pinnedMethod · 0.45
pin_memoryMethod · 0.45
_setitemMethod · 0.45
_getitemMethod · 0.45
_toMethod · 0.45
_lobpcgFunction · 0.45
legacy_loadFunction · 0.45
_unravel_indexFunction · 0.45
_rebuild_tensorFunction · 0.45
_rebuild_tensor_v3Function · 0.45

Calls 4

_stride_or_defaultFunction · 0.85
enable_gradMethod · 0.80
cloneMethod · 0.45
appendMethod · 0.45

Tested by 15

__init__Method · 0.36
__init__Method · 0.36
__init__Method · 0.36
get_training_examplesFunction · 0.36
__init__Method · 0.36
__init__Method · 0.36
_test_ddp_hook_parityMethod · 0.36